Guest User

Untitled

a guest
Jan 19th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
  2.  
  3. guard challenge.previousFailureCount == 0 else {
  4. print("too many failures")
  5. challenge.sender?.cancel(challenge)
  6. completionHandler(.cancelAuthenticationChallenge, nil)
  7. return
  8. }
  9.  
  10. guard challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodNTLM else {
  11. print("unknown authentication method (challenge.protectionSpace.authenticationMethod)")
  12. challenge.sender?.cancel(challenge)
  13. completionHandler(.cancelAuthenticationChallenge, nil)
  14. return
  15. }
  16.  
  17. guard self.doesHaveCredentials() else {
  18. challenge.sender?.cancel(challenge)
  19. completionHandler(.cancelAuthenticationChallenge, nil)
  20. DispatchQueue.main.async {
  21. print("Userdata not set")
  22. };
  23. return
  24. }
  25.  
  26. let credentials = URLCredential(user: self.username!, password: self.password!, persistence: .forSession)
  27. challenge.sender?.use(credentials, for: challenge)
  28. completionHandler(.useCredential, credentials)
  29. }
Add Comment
Please, Sign In to add comment