Skip to content

Open authorize url in SFSafariViewController when available #122

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

Merged
merged 1 commit into from
Jun 26, 2017
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
13 changes: 12 additions & 1 deletion ios/OAuthManager/OAuthManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <SafariServices/SafariServices.h>

#import "OAuthManager.h"
#import "DCTAuth.h"
Expand All @@ -29,6 +30,7 @@ @implementation OAuthManager
static NSString *const AUTH_MANAGER_TAG = @"AUTH_MANAGER";
static OAuthManager *manager;
static dispatch_once_t onceToken;
static SFSafariViewController *safariViewController = nil;

RCT_EXPORT_MODULE(OAuthManager);

Expand Down Expand Up @@ -85,7 +87,13 @@ + (BOOL)setupOAuthHandler:(UIApplication *)application

[authPlatform setURLOpener: ^void(NSURL *URL, DCTAuthPlatformCompletion completion) {
// [sharedManager setPendingAuthentication:YES];
[application openURL:URL];
if ([SFSafariViewController class] != nil) {
safariViewController = [[SFSafariViewController alloc] initWithURL:URL];
UIViewController *viewController = application.keyWindow.rootViewController;
[viewController presentViewController:safariViewController animated:YES completion: nil];
} else {
[application openURL:URL];
}
completion(YES);
}];

Expand All @@ -112,6 +120,9 @@ + (BOOL)handleOpenUrl:(UIApplication *)application openURL:(NSURL *)url
NSString *strUrl = [manager stringHost:url];

if ([manager.callbackUrls indexOfObject:strUrl] != NSNotFound) {
if(safariViewController != nil) {
[safariViewController dismissViewControllerAnimated:YES completion:nil];
}
return [DCTAuth handleURL:url];
}

Expand Down