AadTokenProvider class

Defines the AAD (Azure ActiveDirectory) TokenProvider. This accepts the following credentials from the @azure/ms-rest-nodeauth package:

  • ApplicationTokenCredentials
  • UserTokenCredentials
  • DeviceTokenCredentials
  • MSITokenCredentials (MSIVmTokenCredentials)

Properties

tokenRenewalMarginInSeconds

The number of seconds within which it is good to renew the token. The constant is set to 270 seconds (4.5 minutes). This is because ADAL (adal-node) will return token from cache if it is not within 5 minutes of token expiration. On renewing token within last 4.5 minutes of refresh token, ADAL will be forced to get new access token and will be valid for the next 1 hour. For more context, please see https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/81ff31dd612cae6cd69a9a7452171b7af792be9f/lib/cache-driver.js#L329

tokenValidTimeInSeconds

The number of seconds for which the token is valid. A constant set to 3599 seconds (~1 hour). Adal has a set valid time of 1 hour (3600 seconds) when it refreshes the access token.

Methods

getToken(string)

Gets the jwt token for the specified audience

Constructor Details

AadTokenProvider({ getToken() => Promise<{ accessToken: string, expiresOn?: string | Date, tokenType: string }> })

new AadTokenProvider(credentials: { getToken() => Promise<{ accessToken: string, expiresOn?: string | Date, tokenType: string }> })

Parameters

credentials

{ getToken() => Promise<{ accessToken: string, expiresOn?: string | Date, tokenType: string }> }

Property Details

tokenRenewalMarginInSeconds

The number of seconds within which it is good to renew the token. The constant is set to 270 seconds (4.5 minutes). This is because ADAL (adal-node) will return token from cache if it is not within 5 minutes of token expiration. On renewing token within last 4.5 minutes of refresh token, ADAL will be forced to get new access token and will be valid for the next 1 hour. For more context, please see https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/81ff31dd612cae6cd69a9a7452171b7af792be9f/lib/cache-driver.js#L329

tokenRenewalMarginInSeconds: number

Property Value

number

tokenValidTimeInSeconds

The number of seconds for which the token is valid. A constant set to 3599 seconds (~1 hour). Adal has a set valid time of 1 hour (3600 seconds) when it refreshes the access token.

tokenValidTimeInSeconds: number

Property Value

number

Method Details

getToken(string)

Gets the jwt token for the specified audience

function getToken(audience?: string): Promise<TokenInfo>

Parameters

audience

string

The audience for which the token is desired. If not provided then the Endpoint from the connection string will be applied.

Returns

Promise<TokenInfo>