Inherits from NSObject
Conforms to NSCoding
Declared in AFOAuth2Client.h

Overview

AFOAuthCredential models the credentials returned from an OAuth server, storing the token type, access & refresh tokens, and whether the token is expired.

OAuth credentials can be stored in the user’s keychain, and retrieved on subsequent launches.

Tasks

Accessing Credential Properties

Creating and Initializing Credentials

Setting Refresh Token

Properties

accessToken

@property (readonly, nonatomic) NSString *accessToken
Discussion

The OAuth access token.

Declared In

AFOAuth2Client.h

expired

@property (readonly, nonatomic, assign, getter=isExpired) BOOL expired
Discussion

Whether the OAuth credentials are expired.

Declared In

AFOAuth2Client.h

refreshToken

@property (readonly, nonatomic) NSString *refreshToken
Discussion

The OAuth refresh token.

Declared In

AFOAuth2Client.h

tokenType

@property (readonly, nonatomic) NSString *tokenType
Discussion

The OAuth token type (e.g. “bearer”).

Declared In

AFOAuth2Client.h

Class Methods

credentialWithOAuthToken:tokenType:

+ (instancetype)credentialWithOAuthToken:(NSString *)token tokenType:(NSString *)type
Discussion

Create an OAuth credential from a token string, with a specified type.

Parameters

token

The OAuth token string.

type

The OAuth token type.

Declared In

AFOAuth2Client.h

deleteCredentialWithIdentifier:

+ (BOOL)deleteCredentialWithIdentifier:(NSString *)identifier
Discussion

Deletes the OAuth credential stored with the specified service identifier from the Keychain.

Parameters

identifier

The service identifier associated with the specified credential.

Return Value

Whether or not the credential was deleted from the keychain.

Declared In

AFOAuth2Client.h

retrieveCredentialWithIdentifier:

+ (AFOAuthCredential *)retrieveCredentialWithIdentifier:(NSString *)identifier
Discussion

Retrieves the OAuth credential stored with the specified service identifier from the Keychain.

Parameters

identifier

The service identifier associated with the specified credential.

Return Value

The retrieved OAuth credential.

Declared In

AFOAuth2Client.h

storeCredential:withIdentifier:

+ (BOOL)storeCredential:(AFOAuthCredential *)credential withIdentifier:(NSString *)identifier
Discussion

Stores the specified OAuth credential for a given web service identifier in the Keychain. with the default Keychain Accessibilty of kSecAttrAccessibleWhenUnlocked.

Parameters

credential

The OAuth credential to be stored.

identifier

The service identifier associated with the specified credential.

Return Value

Whether or not the credential was stored in the keychain.

Declared In

AFOAuth2Client.h

storeCredential:withIdentifier:withAccessibility:

+ (BOOL)storeCredential:(AFOAuthCredential *)credential withIdentifier:(NSString *)identifier withAccessibility:(id)securityAccessibility
Discussion

Stores the specified OAuth token for a given web service identifier in the Keychain.

Parameters

identifier

The service identifier associated with the specified token.

securityAccessibility

The Keychain security accessibility to store the credential with.

token

The OAuth credential to be stored.

Return Value

Whether or not the credential was stored in the keychain.

Declared In

AFOAuth2Client.h

Instance Methods

initWithOAuthToken:tokenType:

- (id)initWithOAuthToken:(NSString *)token tokenType:(NSString *)type
Discussion

Initialize an OAuth credential from a token string, with a specified type.

Parameters

token

The OAuth token string.

type

The OAuth token type.

Declared In

AFOAuth2Client.h

setRefreshToken:expiration:

- (void)setRefreshToken:(NSString *)refreshToken expiration:(NSDate *)expiration
Discussion

Set the credential refresh token, with a specified expiration.

Parameters

refreshToken

The OAuth refresh token.

expiration

The expiration of the access token. This must not be nil.

Declared In

AFOAuth2Client.h