OAuthToken
@objc
open class OAuthToken : NSObject, NSCoding
The OAuthToken
is a object that stores the access token and optional refresh token for requests to protected resources.
-
The access token issued by the authorization server.
Declaration
Swift
@objc open fileprivate(set) var accessToken: String
-
The type of token issued.
Declaration
Swift
@objc open fileprivate(set) var tokenType: String
-
The lifetime in seconds of the access token. For example, the value
3600
denotes that the access token will expire in one hour from the time the response was generated.Declaration
Swift
@objc open fileprivate(set) var expiresOn: Date!
-
The date the token was created.
Declaration
Swift
@objc open fileprivate(set) var createdOn: Date!
-
The refresh token that can be used to obtain new access tokens using the same authorization grant.
Declaration
Swift
@objc open fileprivate(set) var refreshToken: String!
-
The dictionary of additional
OAuth
attributes.Declaration
Swift
@objc open fileprivate(set) var additionalData: [String : Any]
-
The scope that the token has authorized.
Declaration
Swift
@objc open fileprivate(set) var scope: [String]!
-
Returns an object initialized from data in a given unarchiver.
Declaration
Swift
required convenience public init?(coder decoder: NSCoder)
Parameters
decoder
An unarchiver object.
Return Value
self
, initialized using the data in decoder. -
Encodes the receiver using a given archiver.
Declaration
Swift
open func encode(with coder: NSCoder)
Parameters
coder
An archiver object.
-
The flag to indicate if the access token has expired.
Declaration
Swift
@objc open var hasTokenExpired: Bool { get }
-
The flag to indicate if the access token should be refreshed.
Remark
true
when 90% of the token lifetime has elapsed since the token created date, otherwisefalse
.Declaration
Swift
@objc open var shouldRefresh: Bool { get }
-
Creates authorization header from token type and access token. The authorization header is used in subsequent HTTP requests.
Declaration
Swift
@objc open func createAuthorizationHeader() -> String
Return Value
An authorization header. For example:
Bearer ABC123
. -
Store the
OAuthToken
toNSUserDefaults
.Remark
This method can be overridden for custom persistence. The forKey parameter is token.Declaration
Swift
@objc open func store()
-
Retrieves the
OAuthToken
fromNSUserDefaults
.Remark
The defaultName parameter is token.Declaration
Swift
@objc open static func retrieve() -> OAuthToken?
Return Value
The persisted instance of
OAuthToken
ornil
.