AppAuth-iOS
AppAuth-iOS copied to clipboard
Invalid error type on programatic cancellation of authorization flow
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:
- Create an authorization flow
- Progtamatically cancel it
- 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.
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:
::OIDErrorCodeProgramCanceledAuthorizationFlowto be passed to thecallbackblock passed toOIDAuthorizationService.presentAuthorizationRequest:presentingViewController:callback:.
Furthermore the documentation forgets to mention the OIDGeneralErrorDomain domain.