AuthorizationCodeCredential Class

Authenticates by redeeming an authorization code previously obtained from Azure Active Directory.

See Azure Active Directory documentation for more information about the authentication flow.

Inheritance
azure.identity.aio._internal.AsyncContextManager
AuthorizationCodeCredential
azure.identity.aio._internal.get_token_mixin.GetTokenMixin
AuthorizationCodeCredential

Constructor

AuthorizationCodeCredential(tenant_id: str, client_id: str, authorization_code: str, redirect_uri: str, **kwargs: Any)

Parameters

tenant_id
str
Required

ID of the application's Azure Active Directory tenant. Also called its "directory" ID.

client_id
str
Required

the application's client ID

authorization_code
str
Required

the authorization code from the user's log-in

redirect_uri
str
Required

The application's redirect URI. Must match the URI used to request the authorization code.

authority
str

Authority of an Azure Active Directory endpoint, for example "login.microsoftonline.com", the authority for Azure Public Cloud (which is the default). AzureAuthorityHosts defines authorities for other clouds.

client_secret
str

One of the application's client secrets. Required only for web apps and web APIs.

Methods

close

Close the credential's transport session.

get_token

Request an access token for scopes.

This method is called automatically by Azure SDK clients.

The first time this method is called, the credential will redeem its authorization code. On subsequent calls the credential will return a cached access token or redeem a refresh token, if it acquired a refresh token upon redeeming the authorization code.

close

Close the credential's transport session.

async close()

get_token

Request an access token for scopes.

This method is called automatically by Azure SDK clients.

The first time this method is called, the credential will redeem its authorization code. On subsequent calls the credential will return a cached access token or redeem a refresh token, if it acquired a refresh token upon redeeming the authorization code.

async get_token(*scopes: str, **kwargs: Any) -> AccessToken

Parameters

scopes
str
Required

desired scopes for the access token. This method requires at least one scope.

tenant_id
str

optional tenant to include in the token request.

Return type

Exceptions

authentication failed. The error's message attribute gives a reason. Any error response from Azure Active Directory is available as the error's response attribute.