diff --git a/React/Views/RCTWKWebView.h b/React/Views/RCTWKWebView.h index 13f98aff542979..04b6e4e4cc50c1 100644 --- a/React/Views/RCTWKWebView.h +++ b/React/Views/RCTWKWebView.h @@ -36,6 +36,7 @@ shouldStartLoadForRequest:(NSMutableDictionary *)request @property (nonatomic, assign) UIEdgeInsets contentInset; @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets; ++ (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential; - (void)postMessage:(NSString *)message; - (void)injectJavaScript:(NSString *)script; - (void)goForward; diff --git a/React/Views/RCTWKWebView.m b/React/Views/RCTWKWebView.m index 9f8e3443ec2bec..79f81df5de0ebd 100644 --- a/React/Views/RCTWKWebView.m +++ b/React/Views/RCTWKWebView.m @@ -10,6 +10,8 @@ #import "RCTAutoInsetsProtocol.h" static NSString *const MessageHanderName = @"ReactNative"; +static NSURLCredential* clientAuthenticationCredential; + @interface RCTWKWebView () @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart; @@ -310,6 +312,25 @@ - (void) webView:(WKWebView *)webView [self setBackgroundColor: _savedBackgroundColor]; } ++ (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential { + clientAuthenticationCredential = credential; +} + +- (void) webView:(WKWebView *)webView + didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge + completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable))completionHandler +{ + if (!clientAuthenticationCredential) { + completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); + return; + } + if ([[challenge protectionSpace] authenticationMethod] == NSURLAuthenticationMethodClientCertificate) { + completionHandler(NSURLSessionAuthChallengeUseCredential, clientAuthenticationCredential); + } else { + completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); +} +} + - (void)evaluateJS:(NSString *)js thenCall: (void (^)(NSString*)) callback {