From d045afbd27a97f7848b9f8ebd03f1078cea060ec Mon Sep 17 00:00:00 2001 From: kononenkoAnton Date: Tue, 25 Jun 2024 13:31:31 -0400 Subject: [PATCH 1/2] fix: ios crash when scenes are enabled --- .../react-native-app-auth/ios/RNAppAuth.m | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) 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": ^{ From 773b378a0bfab4c086821e4169a1da1cfb98bc50 Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Wed, 24 Jul 2024 13:25:51 -0500 Subject: [PATCH 2/2] Changeset --- .changeset/ten-needles-heal.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/ten-needles-heal.md 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