Skip to content

Commit 41126d4

Browse files
authored
Fix iosCustomBrowser not exchanging token (#939)
1 parent 552831e commit 41126d4

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

ios/RNAppAuth.m

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -409,26 +409,30 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
409409
}
410410
}
411411
} else {
412+
OIDAuthStateAuthorizationCallback callback = ^(
413+
OIDAuthState *_Nullable authState,
414+
NSError *_Nullable error
415+
) {
416+
typeof(self) strongSelf = weakSelf;
417+
strongSelf->_currentSession = nil;
418+
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
419+
rnAppAuthTaskId = UIBackgroundTaskInvalid;
420+
if (authState) {
421+
resolve([self formatResponse:authState.lastTokenResponse
422+
withAuthResponse:authState.lastAuthorizationResponse]);
423+
} else {
424+
reject([self getErrorCode: error defaultCode:@"authentication_failed"],
425+
[self getErrorMessage: error], error);
426+
}
427+
};
412428

413429
if(externalUserAgent != nil) {
414-
_currentSession = [OIDAuthorizationService presentAuthorizationRequest:request
430+
_currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request
415431
externalUserAgent:externalUserAgent
416432
callback:callback];
417433
} else {
418-
OIDAuthStateAuthorizationCallback callback = ^(OIDAuthState *_Nullable authState,
419-
NSError *_Nullable error) {
420-
typeof(self) strongSelf = weakSelf;
421-
strongSelf->_currentSession = nil;
422-
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
423-
rnAppAuthTaskId = UIBackgroundTaskInvalid;
424-
if (authState) {
425-
resolve([self formatResponse:authState.lastTokenResponse
426-
withAuthResponse:authState.lastAuthorizationResponse]);
427-
} else {
428-
reject([self getErrorCode: error defaultCode:@"authentication_failed"],
429-
[self getErrorMessage: error], error);
430-
}
431-
};
434+
435+
432436
if (@available(iOS 13, *)) {
433437
_currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request
434438
presentingViewController:presentingViewController

0 commit comments

Comments
 (0)