Skip to content

Commit 8911353

Browse files
jsonblobfacebook-github-bot
authored andcommitted
create api to allow clients to present a client credential for authentication (facebook#22316)
Summary: Pull Request resolved: facebook#22316 Pull Request resolved: facebook#22315 In order for TLS Mutual Auth to work for webviews, the caller must present a credential. Expose a setter that can be called to set a credential. Reviewed By: RSNara Differential Revision: D13095969 fbshipit-source-id: d136556a0030f799651d574b6e47ce38295b108e
1 parent 17ced57 commit 8911353

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

React/Views/RCTWKWebView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
3636
@property (nonatomic, assign) UIEdgeInsets contentInset;
3737
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
3838

39+
+ (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential;
3940
- (void)postMessage:(NSString *)message;
4041
- (void)injectJavaScript:(NSString *)script;
4142
- (void)goForward;

React/Views/RCTWKWebView.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#import "RCTAutoInsetsProtocol.h"
1111

1212
static NSString *const MessageHanderName = @"ReactNative";
13+
static NSURLCredential* clientAuthenticationCredential;
14+
1315

1416
@interface RCTWKWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, UIScrollViewDelegate, RCTAutoInsetsProtocol>
1517
@property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
@@ -310,6 +312,25 @@ - (void) webView:(WKWebView *)webView
310312
[self setBackgroundColor: _savedBackgroundColor];
311313
}
312314

315+
+ (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential {
316+
clientAuthenticationCredential = credential;
317+
}
318+
319+
- (void) webView:(WKWebView *)webView
320+
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
321+
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable))completionHandler
322+
{
323+
if (!clientAuthenticationCredential) {
324+
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
325+
return;
326+
}
327+
if ([[challenge protectionSpace] authenticationMethod] == NSURLAuthenticationMethodClientCertificate) {
328+
completionHandler(NSURLSessionAuthChallengeUseCredential, clientAuthenticationCredential);
329+
} else {
330+
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
331+
}
332+
}
333+
313334
- (void)evaluateJS:(NSString *)js
314335
thenCall: (void (^)(NSString*)) callback
315336
{

0 commit comments

Comments
 (0)