Skip to content

Commit

Permalink
support auth challenge callback via plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
brodybits committed Dec 21, 2021
1 parent 67b0bb2 commit c194fc0
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit c194fc0

Please sign in to comment.