Skip to content

Commit

Permalink
Added support for iOS 13 Web Authentication changes (#234)
Browse files Browse the repository at this point in the history
* Added support fo iOS 13 presentationContextProvider property

* Tweaks
  • Loading branch information
cocojoe committed Sep 18, 2019
1 parent 33f4868 commit e8da8e0
Showing 1 changed file with 23 additions and 1 deletion.
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
if (@available(iOS 13.0, *)) {
authenticationSession.presentationContextProvider = self;
}
#endif
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

0 comments on commit e8da8e0

Please sign in to comment.