AWS.Token — AWS SDK for JavaScript (original) (raw)

We recommend that you migrate to AWS SDK for JavaScript v3. For dates, additional details, and information on how to migrate, please refer to the linked announcement.

Class: AWS.Token

Inherits:

Object

Defined in:

lib/token.js

Overview

Represents AWS token object, which contains token, and optionalexpireTime. Creating a Token object allows you to pass around your token to configuration and service objects.

Note that this class typically does not need to be constructed manually, as the AWS.Config and AWS.Service classes both accept simple options hashes with the two keys. The token from this object will be used automatically in operations which require them.

Expiring and Refreshing Token

Occasionally token can expire in the middle of a long-running application. In this case, the SDK will automatically attempt to refresh the token from the storage location if the Token class implements the refresh() method.

If you are implementing a token storage location, you will want to create a subclass of the Token class and override the refresh() method. This method allows token to be retrieved from the backing store, be it a file system, database, or some network storage. The method should reset the token attributes on the object.

Constructor Summarycollapse

Property Summarycollapse

Method Summarycollapse

Constructor Details

new AWS.Token(options) ⇒ void

Creates a Token object with a given set of information in options hash.

Property Details

expired ⇒ Boolean

Returns whether the token is expired and require a refresh. Used in conjunction with expireTime.

expireTime ⇒ Date

Returns a time when token should be considered expired. Used in conjunction with expired.

expiryWindow ⇒ Integer, Number

token ⇒ String

Returns represents the literal token string. This will typically be a base64 encoded string.

Method Details

get(callback) ⇒ void

Gets the existing token, refreshing them if they are not yet loaded or have expired. Users should call this method before using refresh(), as this will not attempt to reload token when they are already loaded into the object.

getPromise() ⇒ Promise

Returns a 'thenable' promise. Gets the existing token, refreshing it if it's not yet loaded or have expired. Users should call this method before using refresh(), as this will not attempt to reload token when it's already loaded into the object.

Two callbacks can be provided to the then method on the returned promise. The first callback will be called if the promise is fulfilled, and the second callback will be called if the promise is rejected.

needsRefresh() ⇒ Boolean

Note:

Subclasses should override this method to provide custom refresh logic.

Returns whether the Token object should call refresh().

refresh(callback) ⇒ void

Note:

Subclasses should override this class to reset thetoken on the token object and then call the callback with any error information.

Refreshes the token. Users should call get() before attempting to forcibly refresh token.

refreshPromise() ⇒ Promise

Returns a 'thenable' promise. Refreshes the token. Users should call get() before attempting to forcibly refresh token.

Two callbacks can be provided to the then method on the returned promise. The first callback will be called if the promise is fulfilled, and the second callback will be called if the promise is rejected.