Skip to content

Instantly share code, notes, and snippets.

@aleclarson
Last active July 17, 2020 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleclarson/2bd4347a54d08d2abcbb96ebbb573070 to your computer and use it in GitHub Desktop.
Save aleclarson/2bd4347a54d08d2abcbb96ebbb573070 to your computer and use it in GitHub Desktop.
Trust all SSL certificates in React Native (in development only)
diff --git a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
index 274f381..3b573dc 100644
--- a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
+++ b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
@@ -108,6 +108,15 @@ - (void)cancelRequest:(NSURLSessionDataTask *)task
#pragma mark - NSURLSession delegate
+#if DEBUG
+- (void)URLSession:(NSURLSession *)session
+didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
+ completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
+{
+ completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
+}
+#endif
+
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didSendBodyData:(int64_t)bytesSent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment