Class: OAuth2Account

OAuth2Account(options)

new OAuth2Account(options)

Construct a OAuth2Account instance, that will handle fetching and refreshing access tokens.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
id string <optional>

OAuth2 account identifier, or auto-generated uuid

oauth2Client OAuth2Client <optional>

OAuth2Client associated with this OAuth2Account

oauth2Device OAuth2Device <optional>

OAuth2Device associated with this OAuth2Account

oauth2Driver OAuth2Driver <optional>

OAuth2Driver associated with this OAuth2Account

refreshingEnabled string <optional>
true

OAuth2 refresh grant enabled

refreshToken string <optional>

OAuth2 refresh token

accessToken string <optional>

OAuth2 access token

expiresIn Date <optional>

Date object indicating when access token expires

Members

accessToken

Setter for accessToken, also stores it in persistent storage.

accessToken

Getter for accessToken.

expiresIn

Getter for expiresIn.

expiresIn

Setter for expiresIn, stores it in persistent storage.

refreshToken

Getter for refreshToken.

refreshToken

Setter for refreshToken, also stores it in persistent storage.

Methods

destroy()

Method that will clean up event listeners and unsets storage settings.

getAccessTokens(code) → {Promise}

Method that performs a request to retrieve access tokens.

Parameters:
Name Type Description
code string

OAuth2 code

Returns:
Type
Promise

getOAuth2Url() → {string}

Method that returns the OAuth2Url belonging to this OAuth2Account.

Returns:
Type
string

getStoreValues() → {Object}

Returns important values that should be stored persistently.

Returns:
Type
Object

refreshAccessTokens() → {Promise}

Method that performs a request that will refresh the access tokens.

Returns:
Type
Promise

setRefreshTokenTimeout(refreshTimeoutSeconds)

Method that sets a timeout for the next refresh of tokens.

Parameters:
Name Type Description
refreshTimeoutSeconds number

Timeout when tokens need to be refreshed in seconds

setTokens(tokens)

Method that sets access token and refresh token and then emits the token event to update all listeners.

Parameters:
Name Type Description
tokens Object
Properties
Name Type Attributes Description
accessToken string
refreshToken string <optional>
expiresIn Date <optional>