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
Token |
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(Request |
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
- options
- RequestPolicyOptions
Returns
Azure SDK for JavaScript
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for