| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in Mac OS X v10.2 with Safari 1.0 installed. Available in Mac OS X v10.2.7 and later. |
| Companion guide | |
| Declared in | NSURLCredential.h |
| Related sample code |
NSURLCredential is an immutable object representing an authentication credential consisting of authentication information specific to the type of credential and the type of persistent storage to use, if any.
+ credentialForTrust:
+ credentialWithUser:password:persistence:
+ credentialWithIdentity:certificates:persistence:
– initWithIdentity:certificates:persistence:
– initWithTrust:
– initWithUser:password:persistence:
Creates and returns an NSURLCredential object for server trust authentication with a given accepted trust.
+ (NSURLCredential *)credentialForTrust:(SecTrustRef)trust
The accepted trust.
Before creating a server trust credential, it is the responsibility of the delegate of an NSURLConnection object or an NSURLDownload object to evaluate the trust. Do this by calling SecTrustEvaluate, passing it the trust obtained from the serverTrust method of the server’s NSURLProtectionSpace object. If the trust is invalid, the authentication challenge should be cancelled with cancelAuthenticationChallenge:.
NSURLCredential.hCreates and returns an NSURLCredential object for client certificate authentication with a given identity and a given array of client certificates using a given persistence setting.
+ (NSURLCredential *)credentialWithIdentity:(SecIdentityRef)identity certificates:(NSArray *)certArray persistence:(NSURLCredentialPersistence)persistence
The identity for the credential.
An array of one or more SecCertificateRef objects representing certificates for the credential.
The persistence setting for the credential.
NSURLCredential.hCreates and returns an NSURLCredential object for internet password authentication with a given user name and password using a given persistence setting.
+ (NSURLCredential *)credentialWithUser:(NSString *)user password:(NSString *)password persistence:(NSURLCredentialPersistence)persistence
The user for the credential.
The password for user.
The persistence setting for the credential.
An NSURLCredential object with user name user, password password, and using persistence setting persistence.
If persistence is NSURLCredentialPersistencePermanent the credential is stored in the keychain.
NSURLCredential.hReturns an array of SecCertificateRef objects representing the certificates of the credential if it is a client certificate credential.
- (NSArray *)certificates
The certificates of the credential, or nil if this is not a client certificate credential.
NSURLCredential.hReturns a Boolean value that indicates whether the receiver has a password.
- (BOOL)hasPassword
YES if the receiver has a password, NO otherwise.
This method does not attempt to retrieve the password.
If this credential's password is stored in the user’s keychain, password may return NO even if this method returns YES, since getting the password may fail, or the user may refuse access.
NSURLCredential.hReturns the identity of this credential if it is a client certificate credential.
- (SecIdentityRef)identity
The identity of the credential, or NULL if this is not a client certificate credential.
NSURLCredential.hReturns an NSURLCredential object for client certificate authentication initialized with a given identity and a given array of client certificates using a given persistence setting.
- (id)initWithIdentity:(SecIdentityRef)identity certificates:(NSArray *)certArray persistence:(NSURLCredentialPersistence)persistence
The identity for the credential.
An array of one or more SecCertificateRef objects representing certificates for the credential.
The persistence setting for the credential.
NSURLCredential.hReturns an NSURLCredential object for server trust authentication initialized with a given accepted trust.
- (id)initWithTrust:(SecTrustRef)trust
The accepted trust.
Before creating a server trust credential, it is the responsibility of the delegate of an NSURLConnection object or an NSURLDownload object to evaluate the trust. Do this by calling SecTrustEvaluate, passing it the trust obtained from the serverTrust method of the server’s NSURLProtectionSpace object. If the trust is invalid, the authentication challenge should be cancelled with cancelAuthenticationChallenge:.
NSURLCredential.hReturns an NSURLCredential object initialized with a given user name and password using a given persistence setting.
- (id)initWithUser:(NSString *)user password:(NSString *)password persistence:(NSURLCredentialPersistence)persistence
The user for the credential.
The password for user.
The persistence setting for the credential.
An NSURLCredential object initialized with user name user, password password, and using persistence setting persistence.
If persistence is NSURLCredentialPersistencePermanent the credential is stored in the keychain.
NSURLCredential.hReturns the receiver’s password.
- (NSString *)password
The receiver’s password.
If the password is stored in the user’s keychain, this method may result in prompting the user for access.
NSURLCredential.hReturns the receiver’s persistence setting.
- (NSURLCredentialPersistence)persistence
The receiver’s persistence setting.
NSURLCredential.hReturns the receiver’s user name.
- (NSString *)user
The receiver’s user name.
NSURLCredential.hThese constants specify how long the credential will be kept.
typedef enum {
NSURLCredentialPersistenceNone,
NSURLCredentialPersistenceForSession,
NSURLCredentialPersistencePermanent
} NSURLCredentialPersistence;
NSURLCredentialPersistenceNoneCredential won't be stored.
Available in Mac OS X v10.2 and later.
Declared in NSURLCredential.h.
NSURLCredentialPersistenceForSessionCredential will be stored only for this session.
Available in Mac OS X v10.2 and later.
Declared in NSURLCredential.h.
NSURLCredentialPersistencePermanentCredential will be stored in the user’s keychain and shared with other applications.
Available in Mac OS X v10.2 and later.
Declared in NSURLCredential.h.
NSURLCredential.hLast updated: 2009-08-12