OAuthToken

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

    open fileprivate(set) var accessToken: String
  • The type of token issued.

    Declaration

    Swift

    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

    open fileprivate(set) var expiresOn: Date!
  • The date the token was created.

    Declaration

    Swift

    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

    open fileprivate(set) var refreshToken: String!
  • The dictionary of additional OAuth attributes.

    Declaration

    Swift

    open fileprivate(set) var additionalData:[String:Any] = [:]
  • The scope that the token has authorized.

    Declaration

    Swift

    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)
  • Encodes the receiver using a given archiver.

    Declaration

    Swift

    open func encode(with coder: NSCoder)
  • The flag to indicate if the access token has expired.

    Declaration

    Swift

    open var hasTokenExpired: Bool
  • 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, otherwise false.

    Declaration

    Swift

    open var shouldRefresh: Bool
  • Creates authorization header from token type and access token. The authorization header is used in subsequent HTTP requests.

    Declaration

    Swift

    open func createAuthorizationHeader() -> String
  • Store the OAuthToken to NSUserDefaults.

    Remark

    This method can be overridden for custom persistence. The forKey parameter is token.

    Declaration

    Swift

    open func store()
  • Retrieves the OAuthToken from NSUserDefaults.

    Remark

    The defaultName parameter is token.

    Declaration

    Swift

    open static func retrieve() -> OAuthToken?