Class: AWS.Token
- Inherits:
-
Object
- Object
- AWS.Token
- Defined in:
- lib/token.js
Overview
Represents AWS token object, which contains token, and optional
expireTime.
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.
Direct Known Subclasses
Constructor Summary collapse
-
new AWS.Token(options) ⇒ void
constructor
Creates a Token object with a given set of information in options hash.
Property Summary collapse
-
expired ⇒ Boolean
readwrite
Whether the token is expired and require a refresh.
-
expireTime ⇒ Date
readwrite
A time when token should be considered expired.
-
expiryWindow ⇒ Integer, Number
static
readwrite
-
token ⇒ String
readwrite
Represents the literal token string.
Method Summary collapse
-
get(callback) ⇒ void
Gets the existing token, refreshing them if they are not yet loaded or have expired.
-
getPromise() ⇒ Promise
Returns a 'thenable' promise.
-
needsRefresh() ⇒ Boolean
Whether the Token object should call refresh().
-
refresh(callback) ⇒ void
Refreshes the token.
-
refreshPromise() ⇒ Promise
Returns a 'thenable' promise.
Constructor Details
new AWS.Token(options) ⇒ void
Creates a Token object with a given set of information in options hash.
Property Details
expired ⇒ Boolean (readwrite)
Returns whether the token is expired and require a refresh. Used in conjunction with expireTime.
expireTime ⇒ Date (readwrite)
Returns a time when token should be considered expired. Used in conjunction with expired.
expiryWindow ⇒ Integer, Number (static, readwrite)
token ⇒ String (readwrite)
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
Subclasses should override this method to provide custom refresh logic.
Returns whether the Token object should call refresh().
refresh(callback) ⇒ void
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.