Skip to content

Commit

Permalink
Fixes affiliation api session cookie issue when switching netid users.
Browse files Browse the repository at this point in the history
  • Loading branch information
charlon committed Jun 25, 2020
1 parent 695b9b4 commit 2c83756
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions myuw-ios/AppAuthController.swift
Expand Up @@ -471,9 +471,13 @@ extension AppAuthController {
var urlRequest = URLRequest(url: affiliationURL!)

// send id token in authorization header
os_log("ID token: %@", log: .appAuth, type: .error, self.authState?.lastTokenResponse?.idToken ?? "NONE")
os_log("ID token: %@", log: .appAuth, type: .info, self.authState?.lastTokenResponse?.idToken ?? "NONE")
urlRequest.setValue("Bearer \(self.authState?.lastTokenResponse?.idToken ?? "ID_TOKEN")", forHTTPHeaderField: "Authorization")

// disable cookies for API requests - gets around session cookie issues with middleware
urlRequest.httpShouldHandleCookies = false
os_log("affiliation api urlrequest cookies: %@", log: .appAuth, type: .info, urlRequest.httpShouldHandleCookies.description)

// create a task to request affiliations from myuw endpoint
let task = URLSession.shared.dataTask(with: urlRequest) {
data, response, error in DispatchQueue.main.async {
Expand Down Expand Up @@ -566,7 +570,7 @@ extension AppAuthController {
os_log("userAffiliations: %{private}@", log: .appAuth, type: .info, User.userAffiliations)

}

// transition to the main application controller
self.showApplication()

Expand Down
2 changes: 2 additions & 0 deletions myuw-ios/WebViewController.swift
Expand Up @@ -286,6 +286,8 @@ extension WKWebView {
// pass the authorization bearer token in request header
request.setValue("Bearer \(ProcessPool.idToken)", forHTTPHeaderField: "Authorization")

os_log("webview urlrequest cookies: %@", log: .webview, type: .info, request.httpShouldHandleCookies.description)

// load the request
os_log("loading request: %@", log: .webview, type: .info, url.absoluteString)
os_log("loading headers: %@", log: .webview, type: .info, request.allHTTPHeaderFields!)
Expand Down

0 comments on commit 2c83756

Please sign in to comment.