-
Notifications
You must be signed in to change notification settings - Fork 209
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,12 @@ - (void)presentAuthenticationSession:(NSURL *)url { | |
} | ||
self.authenticationSession = nil; | ||
}]; | ||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 | ||
if (@available(iOS 13.0, *)) { | ||
authenticationSession.presentationContextProvider = self; | ||
} | ||
#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; | ||
[(ASWebAuthenticationSession*) self.authenticationSession start]; | ||
} else if (@available(iOS 11.0, *)) { | ||
self.authenticationSession = [[SFAuthenticationSession alloc] | ||
|
@@ -210,4 +224,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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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