-
Notifications
You must be signed in to change notification settings - Fork 201
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
Support for iOS 13 Web Authentication #234
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,14 @@ | |
#define ERROR_CANCELLED @{@"error": @"a0.session.user_cancelled",@"error_description": @"User cancelled the Auth"} | ||
#define ERROR_FAILED_TO_LOAD @{@"error": @"a0.session.failed_load",@"error_description": @"Failed to load url"} | ||
|
||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 | ||
@interface A0Auth0 () <SFSafariViewControllerDelegate, ASWebAuthenticationPresentationContextProviding> | ||
@end | ||
#else | ||
@interface A0Auth0 () <SFSafariViewControllerDelegate> | ||
@end | ||
#endif | ||
|
||
@interface A0Auth0 () <SFSafariViewControllerDelegate> | ||
@property (weak, nonatomic) SFSafariViewController *last; | ||
@property (strong, nonatomic) NSObject *authenticationSession; | ||
|
@@ -84,7 +92,7 @@ - (void)presentAuthenticationSession:(NSURL *)url { | |
RCTResponseSenderBlock callback = self.sessionCallback ? self.sessionCallback : ^void(NSArray *_unused) {}; | ||
|
||
if (@available(iOS 12.0, *)) { | ||
self.authenticationSession = [[ASWebAuthenticationSession alloc] | ||
ASWebAuthenticationSession* authenticationSession = [[ASWebAuthenticationSession alloc] | ||
initWithURL:url callbackURLScheme:callbackURLScheme | ||
completionHandler:^(NSURL * _Nullable callbackURL, | ||
NSError * _Nullable error) { | ||
|
@@ -98,6 +106,10 @@ - (void)presentAuthenticationSession:(NSURL *)url { | |
} | ||
self.authenticationSession = nil; | ||
}]; | ||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 | ||
authenticationSession.presentationContextProvider = self | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requires a |
||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switch to |
||
self.authenticationSession = authenticationSession | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requires a |
||
[(ASWebAuthenticationSession*) self.authenticationSession start]; | ||
} else if (@available(iOS 11.0, *)) { | ||
self.authenticationSession = [[SFAuthenticationSession alloc] | ||
|
@@ -210,4 +222,12 @@ - (UIViewController*)topViewControllerWithRootViewController:(UIViewController*) | |
} | ||
} | ||
|
||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 | ||
#pragma mark - ASWebAuthenticationPresentationContextProviding | ||
|
||
- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session API_AVAILABLE(ios(13.0)){ | ||
return [UIApplication sharedApplication].keyWindow; | ||
} | ||
#endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to
if (@available(iOS 13.0, *)) {
To prevent warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I just tried this on iOS 12.4, and is fails with this suggested change.
Looks like it may need to stay how you originally had it and live with the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you try and compile in Xcode 10.x only with @available it will error as the compiler still sees the code. is a bit of a pain at times