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

[RFC] support authentication challenge callback via plugin #1212

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,30 @@ - (void) webView: (WKWebView *) webView decidePolicyForNavigationAction: (WKNavi
return decisionHandler(NO);
}

- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
// ---
NSLog(@"*** AUTH CHALLENGE ****");

CDVViewController* vc = (CDVViewController*)self.viewController;

// first responder wins:
for (NSString* pluginName in vc.pluginObjects) {
CDVPlugin* plugin = [vc.pluginObjects objectForKey:pluginName];
SEL selector = NSSelectorFromString(@"didReceiveAuthenticationChallenge:completionHandler:");
if ([plugin respondsToSelector:selector]) {
// ---
NSLog(@"found plugin to handle auth challenge, handing over ...");
(((void (*)(id, SEL, id, void(^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)))objc_msgSend)(plugin, selector, challenge, completionHandler));
return;
}
}

// no plugin found, fallback to default behavior
NSLog(@"did not find any plugin to handle auth challenge, fallback to default behavior");
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
}

#pragma mark - Plugin interface

- (void)allowsBackForwardNavigationGestures:(CDVInvokedUrlCommand*)command;
Expand Down