Last active
May 23, 2016 17:08
-
-
Save Daij-Djan/3267225e2f1bd7e8daeca05317f70982 to your computer and use it in GitHub Desktop.
show how to properly ignore invalid ssl certificates while leaving other authentication challenges untouuched
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//setup a new task | |
let configuration = NSURLSessionConfiguration.ephemeralSessionConfiguration() | |
let session = NSURLSession(configuration: configuration, delegate: self, delegateQueue: NSOperationQueue.mainQueue()) | |
let task = session.dataTaskWithURL(url, completionHandler: handleUrlCompleted) | |
task.resume() | |
.... | |
//url session needs to accept invalid certificates | |
func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) { | |
if(challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) { | |
completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)) | |
} | |
else { | |
completionHandler(NSURLSessionAuthChallengeDisposition.PerformDefaultHandling, nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment