AuthorizationCodeCredential class

Enables authentication to Microsoft Entra ID using an authorization code that was obtained through the authorization code flow, described in more detail in the Microsoft Entra ID documentation:

https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow

Constructors

AuthorizationCodeCredential(string, string, string, string, AuthorizationCodeCredentialOptions)

Creates an instance of AuthorizationCodeCredential with the details needed to request an access token using an authentication that was obtained from Microsoft Entra ID.

It is currently necessary for the user of this credential to initiate the authorization code flow to obtain an authorization code to be used with this credential. A full example of this flow is provided here:

https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts

AuthorizationCodeCredential(string, string, string, string, string, AuthorizationCodeCredentialOptions)

Creates an instance of AuthorizationCodeCredential with the details needed to request an access token using an authentication that was obtained from Microsoft Entra ID.

It is currently necessary for the user of this credential to initiate the authorization code flow to obtain an authorization code to be used with this credential. A full example of this flow is provided here:

https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts

Methods

getToken(string | string[], GetTokenOptions)

Authenticates with Microsoft Entra ID and returns an access token if successful. If authentication fails, a CredentialUnavailableError will be thrown with the details of the failure.

Constructor Details

AuthorizationCodeCredential(string, string, string, string, AuthorizationCodeCredentialOptions)

Creates an instance of AuthorizationCodeCredential with the details needed to request an access token using an authentication that was obtained from Microsoft Entra ID.

It is currently necessary for the user of this credential to initiate the authorization code flow to obtain an authorization code to be used with this credential. A full example of this flow is provided here:

https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts

new AuthorizationCodeCredential(tenantId: string, clientId: string, authorizationCode: string, redirectUri: string, options?: AuthorizationCodeCredentialOptions)

Parameters

tenantId

string

The Microsoft Entra tenant (directory) ID or name. 'common' may be used when dealing with multi-tenant scenarios.

clientId

string

The client (application) ID of an App Registration in the tenant.

authorizationCode

string

An authorization code that was received from following the authorization code flow. This authorization code must not have already been used to obtain an access token.

redirectUri

string

The redirect URI that was used to request the authorization code. Must be the same URI that is configured for the App Registration.

options
AuthorizationCodeCredentialOptions

Options for configuring the client which makes the access token request.

AuthorizationCodeCredential(string, string, string, string, string, AuthorizationCodeCredentialOptions)

Creates an instance of AuthorizationCodeCredential with the details needed to request an access token using an authentication that was obtained from Microsoft Entra ID.

It is currently necessary for the user of this credential to initiate the authorization code flow to obtain an authorization code to be used with this credential. A full example of this flow is provided here:

https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts

new AuthorizationCodeCredential(tenantId: string, clientId: string, clientSecret: string, authorizationCode: string, redirectUri: string, options?: AuthorizationCodeCredentialOptions)

Parameters

tenantId

string

The Microsoft Entra tenant (directory) ID or name. 'common' may be used when dealing with multi-tenant scenarios.

clientId

string

The client (application) ID of an App Registration in the tenant.

clientSecret

string

A client secret that was generated for the App Registration

authorizationCode

string

An authorization code that was received from following the authorization code flow. This authorization code must not have already been used to obtain an access token.

redirectUri

string

The redirect URI that was used to request the authorization code. Must be the same URI that is configured for the App Registration.

options
AuthorizationCodeCredentialOptions

Options for configuring the client which makes the access token request.

Method Details

getToken(string | string[], GetTokenOptions)

Authenticates with Microsoft Entra ID and returns an access token if successful. If authentication fails, a CredentialUnavailableError will be thrown with the details of the failure.

function getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>

Parameters

scopes

string | string[]

The list of scopes for which the token will have access.

options
GetTokenOptions

The options used to configure any requests this TokenCredential implementation might make.

Returns

Promise<AccessToken>