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

Support for iOS 13 Web Authentication #234

Merged
merged 2 commits into from
Sep 18, 2019
Merged
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
24 changes: 23 additions & 1 deletion ios/A0Auth0.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -98,6 +106,12 @@ - (void)presentAuthenticationSession:(NSURL *)url {
}
self.authenticationSession = nil;
}];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000

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

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.

Copy link
Member Author

@cocojoe cocojoe Sep 5, 2019

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

if (@available(iOS 13.0, *)) {
authenticationSession.presentationContextProvider = self;
}
#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to } to close the suggested @available check.

self.authenticationSession = authenticationSession;
[(ASWebAuthenticationSession*) self.authenticationSession start];
} else if (@available(iOS 11.0, *)) {
self.authenticationSession = [[SFAuthenticationSession alloc]
Expand Down Expand Up @@ -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