TokenCredential class

TokenCredential is a Credential used to generate a TokenCredentialPolicy. Renew token by setting a new token string value to token property.

Example

const tokenCredential = new TokenCredential("token");
 const pipeline = StorageURL.newPipeline(tokenCredential);

 // List containers
 const serviceURL = new ServiceURL("https://mystorageaccount.blob.core.windows.net", pipeline);

 // Set up a timer to refresh the token
 const timerID = setInterval(() => {
   // Update token by accessing to public tokenCredential.token
   tokenCredential.token = "updatedToken";
   // WARNING: Timer must be manually stopped! It will forbid GC of tokenCredential
   if (shouldStop()) {
     clearInterval(timerID);
   }
 }, 60 * 60 * 1000); // Set an interval time before your token expired
Extends

Constructors

TokenCredential(string)

Creates an instance of TokenCredential.

Properties

token

Mutable token value. You can set a renewed token value to this property, for example, when an OAuth token is expired.

Methods

create(RequestPolicy, RequestPolicyOptions)

Creates a TokenCredentialPolicy object.

Constructor Details

TokenCredential(string)

Creates an instance of TokenCredential.

new TokenCredential(token: string)

Parameters

token

string

Property Details

token

Mutable token value. You can set a renewed token value to this property, for example, when an OAuth token is expired.

token: string

Property Value

string

Method Details

create(RequestPolicy, RequestPolicyOptions)

Creates a TokenCredentialPolicy object.

function create(nextPolicy: RequestPolicy, options: RequestPolicyOptions): TokenCredentialPolicy

Parameters

nextPolicy
RequestPolicy

Returns