okta/okta-oidc-ios

Check if user pressed cancel button?

Closed this issue · 4 comments

I've noticed that when using the OktaOidc.signInWithBrowser method, if the user cancels by pressing the cancel button, the error variable in the callback does not contain the error code of OIDErrorCodeUserCanceledAuthorizationFlow.

try OktaOidc(configuration: configuration).signInWithBrowser(from: self) {
                [weak self] stateManager, error in
                
                if let error = error as NSError? {
                    if error.code == OIDErrorCode.userCanceledAuthorizationFlow.rawValue {
                        // The above always evaluates to false if the user presses the cancel button
                        return
                    } else {
                       ...
                    }
                }
                
                ...
            }

Instead, the error code is 0. Is there a reason for this? What is the proper method of checking if the error received is a result of the user canceling?

Also experiencing this issue. It would be nice to introduce some granularity to the error messages so we could better handle the errors displayed to the user.

Some sort of indication if this was the user's action that initiated the cancel.

Hi @ryanthon , @laughingMan ,

Thanks for reporting this issue. Fully agree that we need to add explicit error code for cancellation scenario. Should be an easy change

Thanks,
Ildar

I've also experienced this issue. Can this also be handled properly in the OktaOidc.signOut method?

Hi huys,
I close the issue as it must be resolved now. There's an error returned, it's type is OktaOidcError. So the code above looks like this now:

switch error as? OktaOidcError {
   case .userCancelledAuthorizationFlow?:
      print("true")
   default:
      print("False")
}