Class

NSURLCredentialStorage

The manager of a shared credentials cache.

Declaration

@interface NSURLCredentialStorage : NSObject

Overview

The shared cache stores and retrieves instances of NSURLCredential. You can store password-based credentials permanently, based on the NSURLCredentialPersistence they were created with. Certificate-based credentials are never stored permanently.

Subclassing Notes

The NSURLCredentialStorage class is meant to be used as-is, but you can subclass it if you have specific needs, such as screening which credentials are stored.

When overriding methods of this class, be aware that methods that take a task parameter are preferred to equivalent methods that do not. Therefore, you should override the task-based methods when subclassing, as follows:

Topics

Getting the Credential Storage

sharedCredentialStorage

The shared URL credential storage instance.

Getting and Setting Default Credentials

- defaultCredentialForProtectionSpace:

Returns the default credential for the specified protection space.

- getDefaultCredentialForProtectionSpace:task:completionHandler:

Gets the default credential for the specified protection space, which is being accessed by the given task, and passes it to the provided completion handler.

- setDefaultCredential:forProtectionSpace:

Sets the default credential for a specified protection space.

- setDefaultCredential:forProtectionSpace:task:

Sets the default credential for a given protection space, which is being accessed by the given task.

Adding and Removing Credentials

- removeCredential:forProtectionSpace:

Removes the specified credential from the credential storage for the specified protection space.

- removeCredential:forProtectionSpace:options:

Removes the specified credential from the credential storage for the specified protection space using the given options.

- removeCredential:forProtectionSpace:options:task:

Removes the specified credential from the credential storage for the specified protection space, on behalf of the given task and using the given options.

- setCredential:forProtectionSpace:

Adds a credential to the credential storage for the specified protection space.

- setCredential:forProtectionSpace:task:

Adds a credential to the credential storage for the specified protection space, on behalf of the specified task.

Retrieving Credentials

allCredentials

The credentials for all available protection spaces.

- credentialsForProtectionSpace:

Returns a dictionary containing the credentials for the specified protection space.

- getCredentialsForProtectionSpace:task:completionHandler:

Gets a dictionary containing the credentials for the specified protection space, on behalf of the given task, and passes the dictionary to the provided completion handler.

Tracking Credential Storage Changes

NSURLCredentialStorageChangedNotification

A notification posted when the set of stored credentials changes.

Relationships

Inherits From

See Also

Authentication and Credentials

Handling an Authentication Challenge

Respond appropriately when a server demands authentication for a URL request.

NSURLAuthenticationChallenge

A challenge from a server requiring authentication from the client.

NSURLCredential

An authentication credential consisting of information specific to the type of credential and the type of persistent storage to use, if any.

NSURLProtectionSpace

A server or an area on a server, commonly referred to as a realm, that requires authentication.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software