When I tried to login to the application using a webservice.
I also set my plist-file like the following
I got the following error. This error
Swift 5.1
Your class has to comply with URLSessionDelegate and implement the "didReceive Challenge" function.
These Apple Developer pages illustrates the issue and provides a lot of insight on how to securely fix this issue:
Handling an Authentication Challenge
Performing Manual Server Trust Authentication
Here is an example of how to fix this issue for Dev or QA environments:
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
#if DEBUG
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
if challenge.protectionSpace.host == "YourTrustedDevOrQaDomain" {
// At this point you can prevent a domain that is pretending to be a trusted domain by challenging the user to present some credentials or a security mechanism for authentication.
if let serverTrust = challenge.protectionSpace.serverTrust {
let credential = URLCredential(trust: serverTrust)
completionHandler(URLSession.AuthChallengeDisposition.useCredential, credential)
}
}
}
#endif
}