diff --git a/.changeset/ten-needles-heal.md b/.changeset/ten-needles-heal.md new file mode 100644 index 00000000..39d408d7 --- /dev/null +++ b/.changeset/ten-needles-heal.md @@ -0,0 +1,5 @@ +--- +"react-native-app-auth": patch +--- + +fix: iOS crash when scenes are enabled diff --git a/packages/react-native-app-auth/ios/RNAppAuth.m b/packages/react-native-app-auth/ios/RNAppAuth.m index eb11aa55..85ddbf57 100644 --- a/packages/react-native-app-auth/ios/RNAppAuth.m +++ b/packages/react-native-app-auth/ios/RNAppAuth.m @@ -130,7 +130,7 @@ - (dispatch_queue_t)methodQueue return; } [self authorizeWithConfiguration: configuration - + redirectUrl: redirectUrl clientId: clientId clientSecret: clientSecret @@ -343,7 +343,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration OIDAuthorizationRequest *request = [[OIDAuthorizationRequest alloc] initWithConfiguration:configuration clientId:clientId - + clientSecret:clientSecret scope:[OIDScopeUtilities scopesWithArray:scopes] redirectURL:[NSURL URLWithString:redirectUrl] @@ -371,12 +371,16 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration UIViewController *presentingViewController = appDelegate.window.rootViewController.view.window ? appDelegate.window.rootViewController : appDelegate.window.rootViewController.presentedViewController; + if (!presentingViewController) { + presentingViewController = RCTPresentedViewController(); + } + #if TARGET_OS_MACCATALYST id externalUserAgent = nil; #elif TARGET_OS_IOS id externalUserAgent = iosCustomBrowser != nil ? [self getCustomBrowser: iosCustomBrowser] : nil; #endif - + OIDAuthorizationCallback callback = ^(OIDAuthorizationResponse *_Nullable authorizationResponse, NSError *_Nullable error) { typeof(self) strongSelf = weakSelf; strongSelf->_currentSession = nil; @@ -391,7 +395,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration }; if (skipCodeExchange) { - + if(externalUserAgent != nil) { _currentSession = [OIDAuthorizationService presentAuthorizationRequest:request externalUserAgent:externalUserAgent @@ -425,14 +429,14 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration [self getErrorMessage: error], error); } }; - + if(externalUserAgent != nil) { _currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; } else { - - + + if (@available(iOS 13, *)) { _currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request presentingViewController:presentingViewController @@ -520,7 +524,7 @@ - (void)endSessionWithConfiguration: (OIDServiceConfiguration *) configuration id externalUserAgent = iosCustomBrowser != nil ? [self getCustomBrowser: iosCustomBrowser] : [self getExternalUserAgentWithPresentingViewController:presentingViewController prefersEphemeralSession:prefersEphemeralSession]; #endif - + _currentSession = [OIDAuthorizationService presentEndSessionRequest: endSessionRequest externalUserAgent: externalUserAgent callback: ^(OIDEndSessionResponse *_Nullable response, NSError *_Nullable error) { @@ -697,7 +701,7 @@ - (NSString*)getErrorCode: (NSError*) error defaultCode: (NSString *) defaultCod #if !TARGET_OS_MACCATALYST - (id)getCustomBrowser: (NSString *) browserType { typedef id (^BrowserBlock)(void); - + NSDictionary *browsers = @{ @"safari": ^{