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

Added logic to fix the deep linking issue. #605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
44 changes: 43 additions & 1 deletion Source/AppAuth/iOS/OIDExternalUserAgentIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ - (BOOL)presentExternalUserAgentRequest:(id<OIDExternalUserAgentRequest>)request
}
strongSelf->_webAuthenticationVC = nil;
if (callbackURL) {
[strongSelf->_session resumeExternalUserAgentFlowWithURL:callbackURL];
if(![self checkIfSchemeExists:callbackURL.absoluteString]) {
[strongSelf->_session resumeExternalUserAgentFlowWithURL:callbackURL];
} else {
[self openScheme:callbackURL];
}
} else {
NSError *safariError =
[OIDErrorUtilities errorWithCode:OIDErrorCodeUserCanceledAuthorizationFlow
Expand Down Expand Up @@ -139,6 +143,11 @@ - (BOOL)presentExternalUserAgentRequest:(id<OIDExternalUserAgentRequest>)request
}
strongSelf->_authenticationVC = nil;
if (callbackURL) {
if (![self checkIfSchemeExists:callbackURL.absoluteString]) {
[strongSelf->_session resumeExternalUserAgentFlowWithURL:callbackURL];
}else{
[self openScheme:callbackURL];
}
[strongSelf->_session resumeExternalUserAgentFlowWithURL:callbackURL];
} else {
NSError *safariError =
Expand Down Expand Up @@ -178,6 +187,39 @@ - (BOOL)presentExternalUserAgentRequest:(id<OIDExternalUserAgentRequest>)request
return openedUserAgent;
}

- (void)openScheme:(NSURL *)URL {
UIApplication *application = [UIApplication sharedApplication];
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
if (@available(iOS 10.0, *)) {
[application openURL:URL options:@{}
completionHandler:^(BOOL success) {
}];
} else {
[application openURL:URL];
}
} else {
[application openURL:URL];
}
}

-(BOOL)checkIfSchemeExists:(NSString *)URLString {
// Check if CFBundleURLSchemes contains the custom scheme first
NSArray *URLTypes = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleURLTypes"];
if (URLTypes != nil) {
for (NSInteger i = 0; i < [URLTypes count]; ++i) {
NSDictionary *schemesDict = [URLTypes objectAtIndex:i];
NSArray *schemes = [schemesDict objectForKey:@"CFBundleURLSchemes"];
for (NSInteger j = 0; j < [schemes count]; ++j) {
NSString *scheme = [schemes objectAtIndex:j];
if ([URLString hasPrefix:scheme]){
return true;
}
}
}
}
return false;
}

- (void)dismissExternalUserAgentAnimated:(BOOL)animated completion:(void (^)(void))completion {
if (!_externalUserAgentFlowInProgress) {
// Ignore this call if there is no authorization flow in progress.
Expand Down