Credentials for asynchronous Azure SDK clients.
Authenticates by redeeming an authorization code previously obtained from Microsoft Entra ID.
See Microsoft Entra ID documentation for more information about the authentication flow.
tenant_id (str) â ID of the applicationâs Microsoft Entra tenant. Also called its âdirectoryâ ID.
client_id (str) â The applicationâs client ID
authorization_code (str) â The authorization code from the userâs log-in
redirect_uri (str) â The applicationâs redirect URI. Must match the URI used to request the authorization code.
authority (str) â Authority of a Microsoft Entra 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.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
Example:
Create an AuthorizationCodeCredential.ïfrom azure.identity.aio import AuthorizationCodeCredential credential = AuthorizationCodeCredential( tenant_id="<tenant_id>", client_id="<client_id>", authorization_code="<auth_code>", redirect_uri="<redirect_uri>", )
Close the credentialâs transport session.
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.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
An access token with the desired scopes.
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason. Any error response from Microsoft Entra ID is available as the errorâs response
attribute.
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. 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.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason. Any error response from Microsoft Entra ID is available as the errorâs response
attribute.
Authenticates by requesting a token from the Azure CLI.
This requires previously logging in to Azure via âaz loginâ, and will use the CLIâs currently logged in identity.
tenant_id (str) â Optional tenant to include in the token request.
subscription (str) â The name or ID of a subscription. Set this to acquire tokens for an account other than the Azure CLIâs current account.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
process_timeout (int) â Seconds to wait for the Azure CLI process to respond. Defaults to 10 seconds.
Example:
Create an AzureCliCredential.ïfrom azure.identity.aio import AzureCliCredential credential = AzureCliCredential()
Calling this method is unnecessary
Request an access token for scopes.
This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesnât cache the tokens it acquires.
scopes (str) â desired scope for the access token. This credential allows only one scope per request. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
An access token with the desired scopes.
CredentialUnavailableError â the credential was unable to invoke the Azure CLI.
ClientAuthenticationError â the credential invoked the Azure CLI but didnât receive an access token.
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesnât cache the tokens it acquires.
scopes (str) â desired scopes for the access token. This credential allows only one scope per request. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the credential was unable to invoke the Azure CLI.
ClientAuthenticationError â the credential invoked the Azure CLI but didnât receive an access token.
Authenticates by requesting a token from the Azure Developer CLI.
Azure Developer CLI is a command-line interface tool that allows developers to create, manage, and deploy resources in Azure. Itâs built on top of the Azure CLI and provides additional functionality specific to Azure developers. It allows users to authenticate as a user and/or a service principal against Microsoft Entra ID. The AzureDeveloperCliCredential authenticates in a development environment and acquires a token on behalf of the logged-in user or service principal in Azure Developer CLI. It acts as the Azure Developer CLI logged-in user or service principal and executes an Azure CLI command underneath to authenticate the application against Microsoft Entra ID.
To use this credential, the developer needs to authenticate locally in Azure Developer CLI using one of the commands below:
Run âazd auth loginâ in Azure Developer CLI to authenticate interactively as a user.
Run âazd auth login âclient-id âclient_idâ âclient-secret âclient_secretâ âtenant-id âtenant_idââ to authenticate as a service principal.
You may need to repeat this process after a certain time period, depending on the refresh token validity in your organization. Generally, the refresh token validity period is a few weeks to a few months. AzureDeveloperCliCredential will prompt you to sign in again.
tenant_id (str) â Optional tenant to include in the token request.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
process_timeout (int) â Seconds to wait for the Azure Developer CLI process to respond. Defaults to 10 seconds.
Example:
Create an AzureDeveloperCliCredential.ïfrom azure.identity.aio import AzureDeveloperCliCredential credential = AzureDeveloperCliCredential()
Calling this method is unnecessary
Request an access token for scopes.
This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesnât cache the tokens it acquires.
scopes (str) â desired scope for the access token. This credential allows only one scope per request. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
An access token with the desired scopes.
CredentialUnavailableError â the credential was unable to invoke the Azure Developer CLI.
ClientAuthenticationError â the credential invoked the Azure Developer CLI but didnât receive an access token.
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesnât cache the tokens it acquires.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the credential was unable to invoke the Azure Developer CLI.
ClientAuthenticationError â the credential invoked the Azure Developer CLI but didnât receive an access token.
Authenticates using Microsoft Entra Workload ID in Azure Pipelines.
This credential enables authentication in Azure Pipelines using workload identity federation for Azure service connections.
tenant_id (str) â The tenant ID for the service connection. Required.
client_id (str) â The client ID for the service connection. Required.
service_connection_id (str) â The service connection ID for the service connection associated with the pipeline. From the service connectionâs configuration page URL in the Azure DevOps web portal, the ID is the value of the âresourceIdâ query parameter. Required.
system_access_token (str) â The pipelineâs System.AccessToken value. It is recommended to assign the value of System.AccessToken to a secure variable in the Azure Pipelines environment. See https://learn.microsoft.com/azure/devops/pipelines/build/variables#systemaccesstoken for more info. Required.
authority (str) â Authority of a Microsoft Entra endpoint, for example âlogin.microsoftonline.comâ, the authority for Azure Public Cloud (which is the default). AzureAuthorityHosts
defines authorities for other clouds.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
Example:
Create an AzurePipelinesCredential.ïimport os from azure.identity.aio import AzurePipelinesCredential credential = AzurePipelinesCredential( system_access_token=os.environ["SYSTEM_ACCESSTOKEN"], tenant_id="<tenant_id>", client_id="<client_id>", service_connection_id="<service_connection_id>", )
Close the credentialâs transport session.
Request an access token for scopes.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
claims (str) â additional claims required in the token, such as those returned in a resource providerâs claims challenge following an authorization failure.
tenant_id (str) â optional tenant to include in the token request.
enable_cae (bool) â indicates whether to enable Continuous Access Evaluation (CAE) for the requested token. Defaults to False.
An access token with the desired scopes.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scope for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Authenticates by requesting a token from Azure PowerShell.
This requires previously logging in to Azure via âConnect-AzAccountâ, and will use the currently logged in identity.
tenant_id (str) â Optional tenant to include in the token request.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
process_timeout (int) â Seconds to wait for the Azure PowerShell process to respond. Defaults to 10 seconds.
Example:
Create an AzurePowerShellCredential.ïfrom azure.identity.aio import AzurePowerShellCredential credential = AzurePowerShellCredential()
Calling this method is unnecessary
Request an access token for scopes.
This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesnât cache the tokens it acquires.
scopes (str) â desired scope for the access token. This credential allows only one scope per request. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
An access token with the desired scopes.
CredentialUnavailableError â the credential was unable to invoke Azure PowerShell, or no account is authenticated
ClientAuthenticationError â the credential invoked Azure PowerShell but didnât receive an access token
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesnât cache the tokens it acquires.
scopes (str) â desired scopes for the access token. TThis credential allows only one scope per request. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the credential was unable to invoke Azure PowerShell, or no account is authenticated
ClientAuthenticationError â the credential invoked Azure PowerShell but didnât receive an access token
Authenticates as a service principal using a certificate.
The certificate must have an RSA private key, because this credential signs assertions using RS256. See Microsoft Entra ID documentation for more information on configuring certificate authentication.
tenant_id (str) â ID of the service principalâs tenant. Also called its âdirectoryâ ID.
client_id (str) â The service principalâs client ID
certificate_path (str) â Optional path to a certificate file in PEM or PKCS12 format, including the private key. If not provided, certificate_data is required.
authority (str) â Authority of a Microsoft Entra endpoint, for example âlogin.microsoftonline.comâ, the authority for Azure Public Cloud (which is the default). AzureAuthorityHosts
defines authorities for other clouds.
certificate_data (bytes) â The bytes of a certificate in PEM or PKCS12 format, including the private key.
password (str or bytes) â The certificateâs password. If a unicode string, it will be encoded as UTF-8. If the certificate requires a different encoding, pass appropriately encoded bytes instead.
cache_persistence_options (TokenCachePersistenceOptions) â Configuration for persistent token caching. If unspecified, the credential will cache tokens in memory.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
Example:
Create a CertificateCredential.ïfrom azure.identity.aio import CertificateCredential credential = CertificateCredential( tenant_id="<tenant_id>", client_id="<client_id>", certificate_path="<path to PEM/PKCS12 certificate>", password="<certificate password if necessary>", ) # Certificate/private key byte data can also be passed directly credential = CertificateCredential( tenant_id="<tenant_id>", client_id="<client_id>", certificate_data=b"<cert data>", )
Close the credentialâs transport session.
Request an access token for scopes.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
claims (str) â additional claims required in the token, such as those returned in a resource providerâs claims challenge following an authorization failure.
tenant_id (str) â optional tenant to include in the token request.
enable_cae (bool) â indicates whether to enable Continuous Access Evaluation (CAE) for the requested token. Defaults to False.
An access token with the desired scopes.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
A sequence of credentials that is itself a credential.
Its get_token()
method calls get_token
on each credential in the sequence, in order, returning the first valid token received. For more information, see https://aka.ms/azsdk/python/identity/credential-chains#chainedtokencredential-overview.
credentials (AsyncTokenCredential) â credential instances to form the chain
Example:
Create a ChainedTokenCredential.ïfrom azure.identity.aio import ChainedTokenCredential, EnvironmentCredential, AzureCliCredential credential_chain = ( # Try EnvironmentCredential first EnvironmentCredential(), # Fallback to Azure CLI if EnvironmentCredential fails AzureCliCredential(), ) credential = ChainedTokenCredential(*credential_chain)
Close the transport sessions of all credentials in the chain.
Asynchronously request a token from each credential, in order, returning the first token received.
If no credential provides a token, raises azure.core.exceptions.ClientAuthenticationError
with an error message from each credential.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
claims (str) â additional claims required in the token, such as those returned in a resource providerâs claims challenge following an authorization failure.
tenant_id (str) â optional tenant to include in the token request.
enable_cae (bool) â indicates whether to enable Continuous Access Evaluation (CAE) for the requested token. Defaults to False.
An access token with the desired scopes.
ClientAuthenticationError â no credential in the chain provided a token
Request a token from each chained credential, in order, returning the first token received.
If no credential provides a token, raises azure.core.exceptions.ClientAuthenticationError
with an error message from each credential.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
ClientAuthenticationError â no credential in the chain provided a token.
Authenticates a service principal with a JWT assertion.
This credential is for advanced scenarios. CertificateCredential
has a more convenient API for the most common assertion scenario, authenticating a service principal with a certificate.
authority (str) â Authority of a Microsoft Entra endpoint, for example âlogin.microsoftonline.comâ, the authority for Azure Public Cloud (which is the default). AzureAuthorityHosts
defines authorities for other clouds.
cache_persistence_options (TokenCachePersistenceOptions) â configuration for persistent token caching. If unspecified, the credential will cache tokens in memory.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
Example:
Create a ClientAssertionCredential.ïfrom azure.identity.aio import ClientAssertionCredential def get_assertion(): return "<client-assertion>" credential = ClientAssertionCredential( tenant_id="<tenant_id>", client_id="<client_id>", func=get_assertion, )
Close the credentialâs transport session.
Request an access token for scopes.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
claims (str) â additional claims required in the token, such as those returned in a resource providerâs claims challenge following an authorization failure.
tenant_id (str) â optional tenant to include in the token request.
enable_cae (bool) â indicates whether to enable Continuous Access Evaluation (CAE) for the requested token. Defaults to False.
An access token with the desired scopes.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Authenticates as a service principal using a client secret.
authority (str) â Authority of a Microsoft Entra endpoint, for example âlogin.microsoftonline.comâ, the authority for Azure Public Cloud (which is the default). AzureAuthorityHosts
defines authorities for other clouds.
cache_persistence_options (TokenCachePersistenceOptions) â Configuration for persistent token caching. If unspecified, the credential will cache tokens in memory.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
Example:
Create a ClientSecretCredential.ïfrom azure.identity.aio import ClientSecretCredential credential = ClientSecretCredential( tenant_id="<tenant_id>", client_id="<client_id>", client_secret="<client_secret>", )
Close the credentialâs transport session.
Request an access token for scopes.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
claims (str) â additional claims required in the token, such as those returned in a resource providerâs claims challenge following an authorization failure.
tenant_id (str) â optional tenant to include in the token request.
enable_cae (bool) â indicates whether to enable Continuous Access Evaluation (CAE) for the requested token. Defaults to False.
An access token with the desired scopes.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
A credential capable of handling most Azure SDK authentication scenarios. See https://aka.ms/azsdk/python/identity/credential-chains#usage-guidance-for-defaultazurecredential.
The identity it uses depends on the environment. When an access token is needed, it requests one using these identities in turn, stopping when one provides a token:
A service principal configured by environment variables. See EnvironmentCredential
for more details.
WorkloadIdentityCredential if environment variable configuration is set by the Azure workload identity webhook.
An Azure managed identity. See ManagedIdentityCredential
for more details.
On Windows only: a user who has signed in with a Microsoft application, such as Visual Studio. If multiple identities are in the cache, then the value of the environment variable AZURE_USERNAME
is used to select which identity to use. See SharedTokenCacheCredential
for more details.
The identity currently logged in to the Azure CLI.
The identity currently logged in to Azure PowerShell.
The identity currently logged in to the Azure Developer CLI.
This default behavior is configurable with keyword arguments.
authority (str) â Authority of a Microsoft Entra endpoint, for example âlogin.microsoftonline.comâ, the authority for Azure Public Cloud (which is the default). AzureAuthorityHosts
defines authorities for other clouds. Managed identities ignore this because they reside in a single cloud.
exclude_workload_identity_credential (bool) â Whether to exclude the workload identity from the credential. Defaults to False.
exclude_developer_cli_credential (bool) â Whether to exclude the Azure Developer CLI from the credential. Defaults to False.
exclude_cli_credential (bool) â Whether to exclude the Azure CLI from the credential. Defaults to False.
exclude_environment_credential (bool) â Whether to exclude a service principal configured by environment variables from the credential. Defaults to False.
exclude_powershell_credential (bool) â Whether to exclude Azure PowerShell. Defaults to False.
exclude_visual_studio_code_credential (bool) â Whether to exclude stored credential from VS Code. Defaults to True.
exclude_managed_identity_credential (bool) â Whether to exclude managed identity from the credential. Defaults to False.
exclude_shared_token_cache_credential (bool) â Whether to exclude the shared token cache. Defaults to False.
managed_identity_client_id (str) â The client ID of a user-assigned managed identity. Defaults to the value of the environment variable AZURE_CLIENT_ID, if any. If not specified, a system-assigned identity will be used.
workload_identity_client_id (str) â The client ID of an identity assigned to the pod. Defaults to the value of the environment variable AZURE_CLIENT_ID, if any. If not specified, the podâs default identity will be used.
workload_identity_tenant_id (str) â Preferred tenant for WorkloadIdentityCredential
. Defaults to the value of environment variable AZURE_TENANT_ID, if any.
shared_cache_username (str) â Preferred username for SharedTokenCacheCredential
. Defaults to the value of environment variable AZURE_USERNAME, if any.
shared_cache_tenant_id (str) â Preferred tenant for SharedTokenCacheCredential
. Defaults to the value of environment variable AZURE_TENANT_ID, if any.
visual_studio_code_tenant_id (str) â Tenant ID to use when authenticating with VisualStudioCodeCredential
. Defaults to the tenant specified in the authentication record file used by the Azure Resources extension.
process_timeout (int) â The timeout in seconds to use for developer credentials that run subprocesses (e.g. AzureCliCredential, AzurePowerShellCredential). Defaults to 10 seconds.
Example:
Create a DefaultAzureCredential.ïfrom azure.identity.aio import DefaultAzureCredential credential = DefaultAzureCredential()
Close the transport sessions of all credentials in the chain.
Asynchronously request an access token for scopes.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
An access token with the desired scopes.
ClientAuthenticationError â authentication failed. The exception has a message attribute listing each authentication attempt and its error message.
Asynchronously request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
ClientAuthenticationError â authentication failed. The exception has a message attribute listing each authentication attempt and its error message.
A credential configured by environment variables.
This credential is capable of authenticating as a service principal using a client secret or a certificate. Configuration is attempted in this order, using these environment variables:
AZURE_TENANT_ID: ID of the service principalâs tenant. Also called its âdirectoryâ ID.
AZURE_CLIENT_ID: the service principalâs client ID
AZURE_CLIENT_SECRET: one of the service principalâs client secrets
AZURE_AUTHORITY_HOST: authority of a Microsoft Entra endpoint, for example âlogin.microsoftonline.comâ, the authority for Azure Public Cloud, which is the default when no value is given.
AZURE_TENANT_ID: ID of the service principalâs tenant. Also called its âdirectoryâ ID.
AZURE_CLIENT_ID: the service principalâs client ID
AZURE_CLIENT_CERTIFICATE_PATH: path to a PEM or PKCS12 certificate file including the private key.
AZURE_CLIENT_CERTIFICATE_PASSWORD: (optional) password of the certificate file, if any.
AZURE_AUTHORITY_HOST: authority of a Microsoft Entra endpoint, for example âlogin.microsoftonline.comâ, the authority for Azure Public Cloud, which is the default when no value is given.
Example:
Create an EnvironmentCredential.ïfrom azure.identity.aio import EnvironmentCredential credential = EnvironmentCredential()
Close the credentialâs transport session.
Asynchronously request an access token for scopes.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
An access token with the desired scopes.
CredentialUnavailableError â environment variable configuration is incomplete
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scope for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â environment variable configuration is incomplete.
Authenticates with an Azure managed identity in any hosting environment which supports managed identities.
This credential defaults to using a system-assigned identity. To configure a user-assigned identity, use one of the keyword arguments. See Microsoft Entra ID documentation for more information about configuring managed identity for applications.
client_id (str) â a user-assigned identityâs client ID or, when using Pod Identity, the client ID of a Microsoft Entra app registration. This argument is supported in all hosting environments.
identity_config (Mapping[str, str]) â a mapping {parameter_name: value}
specifying a user-assigned identity by its object or resource ID, for example {"object_id": "..."}
. Check the documentation for your hosting environment to learn what values it expects.
Example:
Create a ManagedIdentityCredential.ïfrom azure.identity.aio import ManagedIdentityCredential credential = ManagedIdentityCredential() # Can also specify a client ID of a user-assigned managed identity credential = ManagedIdentityCredential( client_id="<client_id>", )
Close the credentialâs transport session.
Asynchronously request an access token for scopes.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scope for the access token. This credential allows only one scope per request. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
An access token with the desired scopes.
CredentialUnavailableError â managed identity isnât available in the hosting environment
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scope for the access token. This credential allows only one scope per request. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â managed identity isnât available in the hosting environment.
Authenticates a service principal via the on-behalf-of flow.
This flow is typically used by middle-tier services that authorize requests to other services with a delegated user identity. Because this is not an interactive authentication flow, an application using it must have admin consent for any delegated permissions before requesting tokens for them. See Microsoft Entra ID documentation for a more detailed description of the on-behalf-of flow.
client_secret (str) â Optional. A client secret to authenticate the service principal. One of client_secret, client_certificate, or client_assertion_func must be provided.
client_certificate (bytes) â Optional. The bytes of a certificate in PEM or PKCS12 format including the private key to authenticate the service principal. One of client_secret, client_certificate, or client_assertion_func must be provided.
client_assertion_func (Callable[[], str]) â Optional. Function that returns client assertions that authenticate the application to Microsoft Entra ID. This function is called each time the credential requests a token. It must return a valid assertion for the target resource.
user_assertion (str) â Required. The access token the credential will use as the user assertion when requesting on-behalf-of tokens.
authority (str) â Authority of a Microsoft Entra endpoint, for example âlogin.microsoftonline.comâ, the authority for Azure Public Cloud (which is the default). AzureAuthorityHosts
defines authorities for other clouds.
password (str or bytes) â A certificate password. Used only when client_certificate is provided. If this value is a unicode string, it will be encoded as UTF-8. If the certificate requires a different encoding, pass appropriately encoded bytes instead.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
Example:
Create an OnBehalfOfCredential.ïfrom azure.identity.aio import OnBehalfOfCredential credential = OnBehalfOfCredential( tenant_id="<tenant_id>", client_id="<client_id>", client_secret="<client_secret>", user_assertion="<access_token>", )
Close the credentialâs underlying HTTP client.
Request an access token for scopes.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
claims (str) â additional claims required in the token, such as those returned in a resource providerâs claims challenge following an authorization failure.
tenant_id (str) â optional tenant to include in the token request.
enable_cae (bool) â indicates whether to enable Continuous Access Evaluation (CAE) for the requested token. Defaults to False.
An access token with the desired scopes.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Authenticates using tokens in the local cache shared between Microsoft applications.
username (str) â Username (typically an email address) of the user to authenticate as. This is required because the local cache may contain tokens for multiple identities.
authority (str) â Authority of a Microsoft Entra endpoint, for example âlogin.microsoftonline.comâ, the authority for Azure Public Cloud (which is the default). AzureAuthorityHosts
defines authorities for other clouds.
tenant_id (str) â a Microsoft Entra tenant ID. Used to select an account when the cache contains tokens for multiple identities.
cache_persistence_options (TokenCachePersistenceOptions) â configuration for persistent token caching. If not provided, the credential will use the persistent cache shared by Microsoft development applications
Whether the shared token cache is supported on the current platform.
True if the shared token cache is supported on the current platform.
Close the credentialâs transport session.
Get an access token for scopes from the shared cache.
If no access token is cached, attempt to acquire one using a cached refresh token.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
claims (str) â additional claims required in the token, such as those returned in a resource providerâs claims challenge following an authorization failure.
tenant_id (str) â optional tenant to include in the token request.
enable_cae (bool) â indicates whether to enable Continuous Access Evaluation (CAE) for the requested token. Defaults to False.
An access token with the desired scopes.
CredentialUnavailableError â the cache is unavailable or contains insufficient user information
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason. Any error response from Microsoft Entra ID is available as the errorâs response
attribute.
Get an access token for scopes from the shared cache.
If no access token is cached, attempt to acquire one using a cached refresh token.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scope for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the cache is unavailable or contains insufficient user information
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason. Any error response from Microsoft Entra ID is available as the errorâs response
attribute.
Authenticates as the Azure user signed in to Visual Studio Code via the âAzure Resourcesâ extension.
This currently only works in Windows/WSL environments and requires the âazure-identity-brokerâ package to be installed.
tenant_id (str) â A Microsoft Entra tenant ID. Defaults to the tenant specified in the authentication record file used by the Azure Resources extension.
additionally_allowed_tenants (List[str]) â Specifies tenants in addition to the specified âtenant_idâ for which the credential may acquire tokens. Add the wildcard value â*â to allow the credential to acquire tokens for any tenant the application can access.
Close the credentialâs transport session.
Request an access token for scopes as the user currently signed in to Visual Studio Code.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
An access token with the desired scopes.
CredentialUnavailableError â the credential cannot retrieve user details from Visual Studio Code
Request an access token for scopes as the user currently signed in to Visual Studio Code.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the credential cannot retrieve user details from Visual Studio Code.
Authenticates using Microsoft Entra Workload ID.
Workload identity authentication is a feature in Azure that allows applications running on virtual machines (VMs) to access other Azure resources without the need for a service principal or managed identity. With workload identity authentication, applications authenticate themselves using their own identity, rather than using a shared service principal or managed identity. Under the hood, workload identity authentication uses the concept of Service Account Credentials (SACs), which are automatically created by Azure and stored securely in the VM. By using workload identity authentication, you can avoid the need to manage and rotate service principals or managed identities for each application on each VM. Additionally, because SACs are created automatically and managed by Azure, you donât need to worry about storing and securing sensitive credentials themselves.
The WorkloadIdentityCredential supports Azure workload identity authentication on Azure Kubernetes and acquires a token using the service account credentials available in the Azure Kubernetes environment. Refer to this workload identity overview for more information.
tenant_id (str) â ID of the applicationâs Microsoft Entra tenant. Also called its âdirectoryâ ID.
client_id (str) â The client ID of a Microsoft Entra app registration.
token_file_path (str) â The path to a file containing a Kubernetes service account token that authenticates the identity.
Example:
Create a WorkloadIdentityCredential.ïfrom azure.identity.aio import WorkloadIdentityCredential credential = WorkloadIdentityCredential( tenant_id="<tenant_id>", client_id="<client_id>", token_file_path="<token_file_path>", ) # Parameters can be omitted if the following environment variables are set: # - AZURE_TENANT_ID # - AZURE_CLIENT_ID # - AZURE_FEDERATED_TOKEN_FILE credential = WorkloadIdentityCredential()
Close the credentialâs transport session.
Request an access token for scopes.
This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
claims (str) â additional claims required in the token, such as those returned in a resource providerâs claims challenge following an authorization failure.
tenant_id (str) â optional tenant to include in the token request.
enable_cae (bool) â indicates whether to enable Continuous Access Evaluation (CAE) for the requested token. Defaults to False.
An access token with the desired scopes.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Request an access token for scopes.
This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients.
scopes (str) â desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
options (TokenRequestOptions) â A dictionary of options for the token request. Unknown options will be ignored. Optional.
An AccessTokenInfo instance containing information about the token.
CredentialUnavailableError â the credential is unable to attempt authentication because it lacks required data, state, or platform support
ClientAuthenticationError â authentication failed. The errorâs message
attribute gives a reason.
Returns a callable that provides a bearer token.
It can be used for instance to write code like:
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider credential = DefaultAzureCredential() bearer_token_provider = get_bearer_token_provider(credential, "https://cognitiveservices.azure.com/.default") # Usage request.headers["Authorization"] = "Bearer " + await bearer_token_provider()
credential (AsyncTokenCredential) â The credential used to authenticate the request.
scopes (str) â The scopes required for the bearer token.
coroutine
A coroutine that returns a bearer token.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4