Class AuthorizationCodeCredential
Authenticates by redeeming an authorization code previously obtained from Microsoft Entra ID. See for more information about the authorization code authentication flow.
Inheritance
Namespace: System.Dynamic.ExpandoObject
Assembly: Azure.Identity.dll
Syntax
public class AuthorizationCodeCredential : Azure.Core.TokenCredential
Constructors
AuthorizationCodeCredential()
AuthorizationCodeCredential(String, String, String, String)
Creates an instance of the ClientSecretCredential with the details needed to authenticate against Microsoft Entra ID with a prefetched authorization code.
Declaration
public AuthorizationCodeCredential (string tenantId, string clientId, string clientSecret, string authorizationCode);
Parameters
|
System.String
tenantId
The Microsoft Entra tenant (directory) ID of the service principal. |
|
System.String
clientId
The client (application) ID of the service principal |
|
System.String
clientSecret
A client secret that was generated for the App Registration used to authenticate the client. |
|
System.String
authorizationCode
The authorization code obtained from a call to authorize. The code should be obtained with all required scopes. See https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow for more information. |
AuthorizationCodeCredential(String, String, String, String, AuthorizationCodeCredentialOptions)
Creates an instance of the ClientSecretCredential with the details needed to authenticate against Microsoft Entra ID with a prefetched authorization code.
Declaration
public AuthorizationCodeCredential (string tenantId, string clientId, string clientSecret, string authorizationCode, Azure.Identity.AuthorizationCodeCredentialOptions options);
Parameters
|
System.String
tenantId
The Microsoft Entra tenant (directory) ID of the service principal. |
|
System.String
clientId
The client (application) ID of the service principal |
|
System.String
clientSecret
A client secret that was generated for the App Registration used to authenticate the client. |
|
System.String
authorizationCode
The authorization code obtained from a call to authorize. The code should be obtained with all required scopes. See for more information. |
|
AuthorizationCodeCredentialOptions
options
Options that allow to configure the management of the requests sent to Microsoft Entra ID. |
AuthorizationCodeCredential(String, String, String, String, TokenCredentialOptions)
Creates an instance of the ClientSecretCredential with the details needed to authenticate against Microsoft Entra ID with a prefetched authorization code.
Declaration
[System.ComponentModel.EditorBrowsable]
public AuthorizationCodeCredential (string tenantId, string clientId, string clientSecret, string authorizationCode, Azure.Identity.TokenCredentialOptions options);
Parameters
|
System.String
tenantId
The Microsoft Entra tenant (directory) ID of the service principal. |
|
System.String
clientId
The client (application) ID of the service principal |
|
System.String
clientSecret
A client secret that was generated for the App Registration used to authenticate the client. |
|
System.String
authorizationCode
The authorization code obtained from a call to authorize. The code should be obtained with all required scopes. See for more information. |
|
TokenCredentialOptions
options
Options that allow to configure the management of the requests sent to Microsoft Entra ID. |
Methods
GetToken(TokenRequestContext, CancellationToken)
Obtains a token from Microsoft Entra ID, using the specified authorization code to authenticate. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness.
Declaration
public override Azure.Core.AccessToken GetToken (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
|
Azure.Core.TokenRequestContext
requestContext
The details of the authentication request. |
|
System.Threading.CancellationToken
cancellationToken
A System.Threading.CancellationToken controlling the request lifetime. |
Returns
|
Azure.Core.AccessToken
An Azure.Core.AccessToken which can be used to authenticate service client calls. |
Exceptions
|
AuthenticationFailedException
Thrown when the authentication failed. |
GetTokenAsync(TokenRequestContext, CancellationToken)
Obtains a token from Microsoft Entra ID, using the specified authorization code to authenticate. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public override System.Threading.Tasks.ValueTask<Azure.Core.AccessToken> GetTokenAsync (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
|
Azure.Core.TokenRequestContext
requestContext
The details of the authentication request. |
|
System.Threading.CancellationToken
cancellationToken
A System.Threading.CancellationToken controlling the request lifetime. |
Returns
|
System.Threading.Tasks.ValueTask<Azure.Core.AccessToken>
An Azure.Core.AccessToken which can be used to authenticate service client calls. |
Exceptions
|
AuthenticationFailedException
Thrown when the authentication failed. |