25.12.2013 Views

URL Loading System Programming Guide - Apple Developer

URL Loading System Programming Guide - Apple Developer

URL Loading System Programming Guide - Apple Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Authentication Challenges and TLS Chain Validation<br />

Responding to an Authentication Challenge<br />

●<br />

●<br />

●<br />

●<br />

HTTP basic authentication (NS<strong>URL</strong>AuthenticationMethodHTTPBasic) requires a user name and<br />

password. Prompt the user for the necessary information and create an NS<strong>URL</strong>Credential object with<br />

credentialWithUser:password:persistence:.<br />

HTTP digest authentication (NS<strong>URL</strong>AuthenticationMethodHTTPDigest), like basic authentication,<br />

requires a user name and password. (The digest is generated automatically.) Prompt the user for the<br />

necessary information and create an NS<strong>URL</strong>Credential object with<br />

credentialWithUser:password:persistence:.<br />

Client certificate authentication (NS<strong>URL</strong>AuthenticationMethodClientCertificate) requires the<br />

system identity and all certificates needed to authenticate with the server. Create an NS<strong>URL</strong>Credential<br />

object with credentialWithIdentity:certificates:persistence:.<br />

Server trust authentication (NS<strong>URL</strong>AuthenticationMethodServerTrust) requires a trust provided by<br />

the protection space of the authentication challenge. Create an NS<strong>URL</strong>Credential object with<br />

credentialForTrust:.<br />

After you’ve created the NS<strong>URL</strong>Credential object:<br />

●<br />

●<br />

For NS<strong>URL</strong>Session, pass the object to the authentication challenge’s sender using the provided completion<br />

handler block.<br />

For NS<strong>URL</strong>Connection and NS<strong>URL</strong>Download, pass the object to the authentication challenge’s sender<br />

with useCredential:forAuthenticationChallenge:.<br />

Continuing Without Credentials<br />

If the delegate chooses not to provide a credential for the authentication challenge, it can attempt to continue<br />

without one.<br />

●<br />

For NS<strong>URL</strong>Session, pass one of the following values to the provided completion handler block:<br />

NS<strong>URL</strong>SessionAuthChallengePerformDefaultHandling processes the request as though the<br />

delegate did not provide a delegate method to handle the challenge.<br />

NS<strong>URL</strong>SessionAuthChallengeRejectProtectionSpace rejects the challenge. Depending on the<br />

authentication types allowed by the server’s response, the <strong>URL</strong> loading class may call this delegate method<br />

more than once, for additional protection spaces.<br />

●<br />

For NS<strong>URL</strong>Connection and NS<strong>URL</strong>Download, call<br />

continueWithoutCredentialsForAuthenticationChallenge: on [challenge sender].<br />

Depending on the protocol implementation, continuing without credentials may either cause the connection<br />

to fail, resulting in a connectionDidFailWithError: message, or return alternate <strong>URL</strong> contents that<br />

don’t require authentication.<br />

2013-10-22 | Copyright © 2003, 2013 <strong>Apple</strong> Inc. All Rights Reserved.<br />

55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!