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 authored and lbalmaceda committed Sep 30, 2019
1 parent 56af46a commit b095109
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions ios/A0Auth0.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 @@ -83,7 +91,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 @@ -97,6 +105,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 @@ -209,4 +223,12 @@ - (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)
}
}

@end
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
#pragma mark - ASWebAuthenticationPresentationContextProviding

- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session API_AVAILABLE(ios(13.0)){
return [UIApplication sharedApplication].keyWindow;
}
#endif

@end

0 comments on commit b095109

Please sign in to comment.