Skip to content

Commit

Permalink
Adding error case for when oidc flow is cancelled by user (okta#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
brennerryan-okta authored Jan 19, 2021
1 parent 1b890e6 commit 8227128
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ class OktaOidcBrowserTask: OktaOidcTask {
defer { self.userAgentSession = nil }

guard let authResponse = authorizationResponse else {
return callback(nil, OktaOidcError.APIError("Authorization Error: \(error!.localizedDescription)"))
guard let error = error else {
return callback(nil, OktaOidcError.APIError("Authorization Error"))
}
if ((error as NSError).code == OKTErrorCode.userCanceledAuthorizationFlow.rawValue) {
return callback(nil, OktaOidcError.userCancelledAuthorizationFlow)
} else {
return callback(nil, OktaOidcError.APIError("Authorization Error: \(error.localizedDescription)"))
}
}
callback(authResponse, nil)
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/OktaOidc/Common/OktaOidcError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public enum OktaOidcError: Error {
case parseFailure
case missingIdToken
case unexpectedAuthCodeResponse
case userCancelledAuthorizationFlow
case unableToGetAuthCode
case redirectServerError(String)
}
Expand Down Expand Up @@ -75,6 +76,8 @@ extension OktaOidcError: LocalizedError {
return NSLocalizedString("ID token needed to fulfill this operation.", comment: "")
case .unexpectedAuthCodeResponse:
return NSLocalizedString("Unexpected response format while retrieving authorization code.", comment: "")
case .userCancelledAuthorizationFlow:
return NSLocalizedString("User cancelled current session", comment: "")
case .unableToGetAuthCode:
return NSLocalizedString("Unable to get authorization code.", comment: "")
case .redirectServerError(error: let error):
Expand Down

0 comments on commit 8227128

Please sign in to comment.