Class: TokenManager

TokenManager(config, requestManager)

Manager for API access abd refresh tokens

Constructor

new TokenManager(config, requestManager)

Parameters:
Name Type Description
config Config The config object
requestManager APIRequestManager The API Request Manager
Source:

Methods

exchangeToken(accessToken, scopes, resourceopt, optionsopt) → {Promise.<TokenInfo>}

Exchange a valid access token for one with a lower scope, or delegated to an external user identifier.
Parameters:
Name Type Attributes Description
accessToken string The valid access token to exchange
scopes string | Array.<string> The scope(s) of the new access token
resource string <optional>
The absolute URL of an API resource to restrict the new token to
options Object <optional>
Optional parameters
Properties
Name Type Attributes Description
tokenRequestOptions TokenRequestOptions <optional>
Sets optional behavior for the token grant
actor ActorParams <optional>
Optional actor parameters for creating annotator tokens
sharedLink SharedLinkParams <optional>
Optional shared link parameters for creating tokens using shared links
Source:
Returns:
Promise resolving to the new token info
Type
Promise.<TokenInfo>

exchangeToken(accessToken, scopes, resourceopt, optionsopt) → {Promise.<TokenInfo>}

Exchange a valid access token for one with a lower scope, or delegated to an external user identifier.
Parameters:
Name Type Attributes Description
accessToken string The valid access token to exchange
scopes string | Array.<string> The scope(s) of the new access token
resource string <optional>
The absolute URL of an API resource to restrict the new token to
options Object <optional>
Optional parameters
Properties
Name Type Attributes Description
tokenRequestOptions TokenRequestOptions <optional>
Sets optional behavior for the token grant
actor ActorParams <optional>
Optional actor parameters for creating annotator tokens
sharedLink SharedLinkParams <optional>
Optional shared link parameters for creating tokens using shared links
Source:
Returns:
Promise resolving to the new token info
Type
Promise.<TokenInfo>

getTokensAuthorizationCodeGrant(authorizationCode, optionsopt) → {Promise.<TokenInfo>}

Acquires token info using an authorization code
Parameters:
Name Type Attributes Description
authorizationCode string authorization code issued by Box
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensAuthorizationCodeGrant(authorizationCode, optionsopt) → {Promise.<TokenInfo>}

Acquires token info using an authorization code
Parameters:
Name Type Attributes Description
authorizationCode string authorization code issued by Box
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensClientCredentialsGrant(optionsopt) → {Promise.<TokenInfo>}

Acquires token info using the client credentials grant.
Parameters:
Name Type Attributes Description
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensClientCredentialsGrant(optionsopt) → {Promise.<TokenInfo>}

Acquires token info using the client credentials grant.
Parameters:
Name Type Attributes Description
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensJWTGrant(type, id, optionsopt) → {Promise.<TokenInfo>}

Gets tokens for enterprise administration of app users
Parameters:
Name Type Attributes Description
type string The type of token to create, "user" or "enterprise"
id string The ID of the enterprise to generate a token for
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensJWTGrant(type, id, optionsopt) → {Promise.<TokenInfo>}

Gets tokens for enterprise administration of app users
Parameters:
Name Type Attributes Description
type string The type of token to create, "user" or "enterprise"
id string The ID of the enterprise to generate a token for
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensRefreshGrant(refreshToken, optionsopt) → {Promise.<TokenInfo>}

Refreshes the access and refresh tokens for a given refresh token.
Parameters:
Name Type Attributes Description
refreshToken string A valid OAuth refresh token
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensRefreshGrant(refreshToken, optionsopt) → {Promise.<TokenInfo>}

Refreshes the access and refresh tokens for a given refresh token.
Parameters:
Name Type Attributes Description
refreshToken string A valid OAuth refresh token
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

isAccessTokenValid(tokenInfo, bufferMSopt) → {boolean}

Given a TokenInfo object, returns whether its access token is expired. An access token is considered expired once its TTL surpasses the current time outside of the given buffer. This is a public method so that other modules may check the validity of their tokens.
Parameters:
Name Type Attributes Description
tokenInfo TokenInfo the token info to be written
bufferMS int <optional>
An optional buffer we'd like to test against. The greater this buffer, the more aggressively we'll call a token invalid.
Source:
Returns:
True if token is valid outside of buffer, otherwise false
Type
boolean

isAccessTokenValid(tokenInfo, bufferMSopt) → {boolean}

Given a TokenInfo object, returns whether its access token is expired. An access token is considered expired once its TTL surpasses the current time outside of the given buffer. This is a public method so that other modules may check the validity of their tokens.
Parameters:
Name Type Attributes Description
tokenInfo TokenInfo the token info to be written
bufferMS int <optional>
An optional buffer we'd like to test against. The greater this buffer, the more aggressively we'll call a token invalid.
Source:
Returns:
True if token is valid outside of buffer, otherwise false
Type
boolean

retryJWTGrant(claims, jwtOptionsopt, keyParams, params, optionsopt, error, numRetries) → {Promise.<TokenInfo>}

Attempt a retry if possible and create a new JTI claim. If the request hasn't exceeded it's maximum number of retries, re-execute the request (after the retry interval). Otherwise, propagate a new error.
Parameters:
Name Type Attributes Description
claims Object JTI claims object
jwtOptions Object <optional>
JWT options for the signature
keyParams Object Key JWT parameters object that contains the private key and the passphrase
params Object Should contain all params expected by Box OAuth2 token endpoint
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
error Error Error from the previous JWT request
numRetries int Number of retries attempted
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

retryJWTGrant(claims, jwtOptionsopt, keyParams, params, optionsopt, error, numRetries) → {Promise.<TokenInfo>}

Attempt a retry if possible and create a new JTI claim. If the request hasn't exceeded it's maximum number of retries, re-execute the request (after the retry interval). Otherwise, propagate a new error.
Parameters:
Name Type Attributes Description
claims Object JTI claims object
jwtOptions Object <optional>
JWT options for the signature
keyParams Object Key JWT parameters object that contains the private key and the passphrase
params Object Should contain all params expected by Box OAuth2 token endpoint
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
error Error Error from the previous JWT request
numRetries int Number of retries attempted
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

revokeTokens(token, optionsopt) → {Promise}

Revokes a token pair associated with a given access or refresh token.
Parameters:
Name Type Attributes Description
token string A valid access or refresh token to revoke
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving if the revoke succeeds
Type
Promise

revokeTokens(token, optionsopt) → {Promise}

Revokes a token pair associated with a given access or refresh token.
Parameters:
Name Type Attributes Description
token string A valid access or refresh token to revoke
options TokenRequestOptions <optional>
Sets optional behavior for the token grant
Source:
Returns:
Promise resolving if the revoke succeeds
Type
Promise