AppAuth-iOS icon indicating copy to clipboard operation
AppAuth-iOS copied to clipboard

Invalid error type on programatic cancellation of authorization flow

Open andraskadar opened this issue 4 years ago • 1 comments

Describe the bug OIDExternalUserAgentSession's cancel method writes in the documentation that on call, it will throw an OIDErrorCodeProgramCanceledAuthorizationFlow error, but in reality a OIDErrorCodeUserCanceledAuthorizationFlow error is thrown in the implementation.

To Reproduce Steps to reproduce the behavior:

  1. Create an authorization flow
  2. Progtamatically cancel it
  3. Observe the thrown error
let request = OIDAuthorizationRequest(...
let currentAuthorizationFlow = OIDAuthState.authState(...) { authState, error in
  XCTAssertEqual((error as NSError).code, OIDErrorCode.programCanceledAuthorizationFlow.rawValue)
}
currentAuthorizationFlow.cancel()

Expected behavior Expect a OIDErrorCodeProgramCanceledAuthorizationFlow error when OIDExternalUserAgentSession's login is programmatically canceled.

andraskadar avatar Mar 22 '21 10:03 andraskadar

Bumping this issue. I was about to report the same issue. Either the documentation is wrong or the implementation. The OIDAuthorizationService implements the following:

- (void)cancelWithCompletion:(nullable void (^)(void))completion {
  [_externalUserAgent dismissExternalUserAgentAnimated:YES completion:^{
      NSError *error = [OIDErrorUtilities errorWithCode:OIDErrorCodeUserCanceledAuthorizationFlow
                                        underlyingError:nil
                                            description:@"Authorization flow was cancelled."];
      [self didFinishWithResponse:nil error:error];
      if (completion) completion();
  }];
}

While the OIDExternalUserAgentSession protocol says this:

Will cause an error with code: ::OIDErrorCodeProgramCanceledAuthorizationFlow to be passed to the callback block passed to OIDAuthorizationService.presentAuthorizationRequest:presentingViewController:callback:.

Furthermore the documentation forgets to mention the OIDGeneralErrorDomain domain.

DevAndArtist avatar Apr 11 '21 10:04 DevAndArtist