diff --git a/React/Views/RCTWKWebView.h b/React/Views/RCTWKWebView.h index 13f98aff54..04b6e4e4cc 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 9f8e3443ec..79f81df5de 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 @@ static NSString *const MessageHanderName = @"ReactNative"; [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 {