diff --git a/ios/RNAppAuth.m b/ios/RNAppAuth.m index 3ef14c77..eb11aa55 100644 --- a/ios/RNAppAuth.m +++ b/ios/RNAppAuth.m @@ -409,26 +409,30 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration } } } else { + OIDAuthStateAuthorizationCallback callback = ^( + OIDAuthState *_Nullable authState, + NSError *_Nullable error + ) { + typeof(self) strongSelf = weakSelf; + strongSelf->_currentSession = nil; + [UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId]; + rnAppAuthTaskId = UIBackgroundTaskInvalid; + if (authState) { + resolve([self formatResponse:authState.lastTokenResponse + withAuthResponse:authState.lastAuthorizationResponse]); + } else { + reject([self getErrorCode: error defaultCode:@"authentication_failed"], + [self getErrorMessage: error], error); + } + }; if(externalUserAgent != nil) { - _currentSession = [OIDAuthorizationService presentAuthorizationRequest:request + _currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; } else { - OIDAuthStateAuthorizationCallback callback = ^(OIDAuthState *_Nullable authState, - NSError *_Nullable error) { - typeof(self) strongSelf = weakSelf; - strongSelf->_currentSession = nil; - [UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId]; - rnAppAuthTaskId = UIBackgroundTaskInvalid; - if (authState) { - resolve([self formatResponse:authState.lastTokenResponse - withAuthResponse:authState.lastAuthorizationResponse]); - } else { - reject([self getErrorCode: error defaultCode:@"authentication_failed"], - [self getErrorMessage: error], error); - } - }; + + if (@available(iOS 13, *)) { _currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request presentingViewController:presentingViewController