Skip to content

Migrate authentication to LabsPlatformSwift #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
37 changes: 17 additions & 20 deletions PennMobile.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

329 changes: 0 additions & 329 deletions PennMobile/Auth/OAuth2NetworkManager.swift

This file was deleted.

20 changes: 2 additions & 18 deletions PennMobile/Clubs/TicketingAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,8 @@ class TicketingAPI {
return URL(string: "\(baseURL)/api/tickets/\(pathComponent)/")
}

func getSession() async throws -> URLSession {
guard let accessToken = try? await OAuth2NetworkManager.instance.getAccessToken() else {
throw NetworkingError.authenticationError
}

// HACK: iOS doesn't preserve Authorization headers during redirects
// (It also doesn't support setting Authorization headers in general apparently)
let config = URLSessionConfiguration.default
config.httpAdditionalHeaders = [
"Authorization": "Bearer \(accessToken.value)",
"X-Authorization": "Bearer \(accessToken.value)"
]

return URLSession(configuration: config)
}

func getTicket(id: String) async throws -> Ticket? {
let session = try await getSession()
let session = try await URLSession(authenticationMode: .accessToken)

guard let url = ticketUrl(forId: id) else {
return nil
Expand All @@ -76,7 +60,7 @@ class TicketingAPI {
}

@discardableResult func updateAttendance(id: String, to attended: Bool) async throws -> Ticket {
let session = try await getSession()
let session = try await URLSession(authenticationMode: .accessToken)

guard let url = ticketUrl(forId: id) else {
throw ScannedTicket.InvalidReason.notFound
Expand Down
Loading