Class AuthorizationCodeCredential
Authenticates by redeeming an authorization code previously obtained from Microsoft Entra ID. See https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow for more information about the authorization code authentication flow.
public class AuthorizationCodeCredential : TokenCredential
- Inheritance
-
AuthorizationCodeCredential
Constructors
AuthorizationCodeCredential()
Protected constructor for mocking.
protected 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.
public AuthorizationCodeCredential(string tenantId, string clientId, string clientSecret, string authorizationCode)
Parameters
tenantId
stringThe Microsoft Entra tenant (directory) ID of the service principal.
clientId
stringThe client (application) ID of the service principal
clientSecret
stringA client secret that was generated for the App Registration used to authenticate the client.
authorizationCode
stringThe 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.
public AuthorizationCodeCredential(string tenantId, string clientId, string clientSecret, string authorizationCode, AuthorizationCodeCredentialOptions options)
Parameters
tenantId
stringThe Microsoft Entra tenant (directory) ID of the service principal.
clientId
stringThe client (application) ID of the service principal
clientSecret
stringA client secret that was generated for the App Registration used to authenticate the client.
authorizationCode
stringThe 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.
options
AuthorizationCodeCredentialOptionsOptions 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.
public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken = default)
Parameters
requestContext
TokenRequestContextThe details of the authentication request.
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- AccessToken
An Azure.Core.AccessToken which can be used to authenticate service client calls.
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.
public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken = default)
Parameters
requestContext
TokenRequestContextThe details of the authentication request.
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- ValueTask<AccessToken>
An Azure.Core.AccessToken which can be used to authenticate service client calls.