Skip to content

Commit

Permalink
fix: move credential override off main thread (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seavenly authored Oct 24, 2023
1 parent d4a0839 commit b30c2f8
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions Sources/PayPalMessages/PayPalMessageModalViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,22 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
) {
guard let serverTrust = challenge.protectionSpace.serverTrust else {
return completionHandler(.useCredential, nil)
}
switch environment {
case .local, .stage:
// Allow webview to connect to webpage using invalid local HTTPS certs
let exceptions = SecTrustCopyExceptions(serverTrust)
SecTrustSetExceptions(serverTrust, exceptions)
default: break
case .live, .sandbox:
completionHandler(.performDefaultHandling, nil)
case .stage, .local:
guard let serverTrust = challenge.protectionSpace.serverTrust else {
return completionHandler(.performDefaultHandling, nil)
}
// Credential override methods warn when run on the main thread
DispatchQueue.global(qos: .background).async {
// Allow webview to connect to webpage using self-signed HTTPS certs
let exceptions = SecTrustCopyExceptions(serverTrust)
SecTrustSetExceptions(serverTrust, exceptions)

completionHandler(.useCredential, URLCredential(trust: serverTrust))
}
}
completionHandler(.useCredential, URLCredential(trust: serverTrust))
}

func webView(
Expand Down

0 comments on commit b30c2f8

Please sign in to comment.