Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: iOS crash when scenes are enabled #995

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-needles-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-native-app-auth": patch
---

fix: iOS crash when scenes are enabled
22 changes: 13 additions & 9 deletions packages/react-native-app-auth/ios/RNAppAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ - (dispatch_queue_t)methodQueue
return;
}
[self authorizeWithConfiguration: configuration

redirectUrl: redirectUrl
clientId: clientId
clientSecret: clientSecret
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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<OIDExternalUserAgent> externalUserAgent = nil;
#elif TARGET_OS_IOS
id<OIDExternalUserAgent> externalUserAgent = iosCustomBrowser != nil ? [self getCustomBrowser: iosCustomBrowser] : nil;
#endif

OIDAuthorizationCallback callback = ^(OIDAuthorizationResponse *_Nullable authorizationResponse, NSError *_Nullable error) {
typeof(self) strongSelf = weakSelf;
strongSelf->_currentSession = nil;
Expand All @@ -391,7 +395,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
};

if (skipCodeExchange) {

if(externalUserAgent != nil) {
_currentSession = [OIDAuthorizationService presentAuthorizationRequest:request
externalUserAgent:externalUserAgent
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -520,7 +524,7 @@ - (void)endSessionWithConfiguration: (OIDServiceConfiguration *) configuration
id<OIDExternalUserAgent> 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) {
Expand Down Expand Up @@ -697,7 +701,7 @@ - (NSString*)getErrorCode: (NSError*) error defaultCode: (NSString *) defaultCod
#if !TARGET_OS_MACCATALYST
- (id<OIDExternalUserAgent>)getCustomBrowser: (NSString *) browserType {
typedef id<OIDExternalUserAgent> (^BrowserBlock)(void);

NSDictionary *browsers = @{
@"safari":
^{
Expand Down