Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- guard challenge.previousFailureCount == 0 else {
- print("too many failures")
- challenge.sender?.cancel(challenge)
- completionHandler(.cancelAuthenticationChallenge, nil)
- return
- }
- guard challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodNTLM else {
- print("unknown authentication method (challenge.protectionSpace.authenticationMethod)")
- challenge.sender?.cancel(challenge)
- completionHandler(.cancelAuthenticationChallenge, nil)
- return
- }
- guard self.doesHaveCredentials() else {
- challenge.sender?.cancel(challenge)
- completionHandler(.cancelAuthenticationChallenge, nil)
- DispatchQueue.main.async {
- print("Userdata not set")
- };
- return
- }
- let credentials = URLCredential(user: self.username!, password: self.password!, persistence: .forSession)
- challenge.sender?.use(credentials, for: challenge)
- completionHandler(.useCredential, credentials)
- }
Add Comment
Please, Sign In to add comment