Microsoft Azure Identity Library for Python
The Azure Identity library provides Microsoft Entra ID (formerly Azure Active Directory) token authentication support across the Azure SDK. It provides a set of TokenCredential
implementations, which can be used to construct Azure SDK clients that support Microsoft Entra token authentication.
Source code | Package (PyPI) | Package (Conda) | API reference documentation | Microsoft Entra ID documentation
Install Azure Identity with pip:
pip install azure-identity
When debugging and executing code locally, it's typical for developers to use their own accounts for authenticating calls to Azure services. The Azure Identity library supports authenticating through developer tools to simplify local development.
Developers using Visual Studio Code can use the Azure Account extension to authenticate via the editor. Apps using DefaultAzureCredential
or VisualStudioCodeCredential
can then use this account to authenticate calls in their app when running locally.
To authenticate in Visual Studio Code, ensure the Azure Account extension is installed. Once installed, open the Command Palette and run the Azure: Sign In command.
It's a known issue that VisualStudioCodeCredential
doesn't work with Azure Account extension versions newer than 0.9.11. A long-term fix to this problem is in progress. In the meantime, consider authenticating via the Azure CLI.
DefaultAzureCredential
and AzureCliCredential
can authenticate as the user signed in to the Azure CLI. To sign in to the Azure CLI, run az login
. On a system with a default web browser, the Azure CLI will launch the browser to authenticate a user.
When no default browser is available, az login
will use the device code authentication flow. This flow can also be selected manually by running az login --use-device-code
.
Developers coding outside of an IDE can also use the Azure Developer CLI to authenticate. Applications using the DefaultAzureCredential
or the AzureDeveloperCliCredential
can then use this account to authenticate calls in their application when running locally.
To authenticate with the Azure Developer CLI, users can run the command azd auth login
. For users running on a system with a default web browser, the Azure Developer CLI will launch the browser to authenticate the user.
For systems without a default web browser, the azd auth login --use-device-code
command will use the device code authentication flow.
A credential is a class that contains or can obtain the data needed for a service client to authenticate requests. Service clients across the Azure SDK accept a credential instance when they're constructed, and use that credential to authenticate requests.
The Azure Identity library focuses on OAuth authentication with Microsoft Entra ID. It offers various credential classes capable of acquiring a Microsoft Entra access token. See the Credential classes section below for a list of this library's credential classes.
DefaultAzureCredential
is appropriate for most applications that will run in Azure because it combines common production credentials with development credentials. DefaultAzureCredential
attempts to authenticate via the following mechanisms, in this order, stopping when one succeeds:
Note:
DefaultAzureCredential
is intended to simplify getting started with the library by handling common scenarios with reasonable default behaviors. Developers who want more control or whose scenario isn't served by the default settings should use other credential types.
DefaultAzureCredential
will read account information specified via environment variables and use it to authenticate.DefaultAzureCredential
will authenticate with it.DefaultAzureCredential
will authenticate with it.az login
command, DefaultAzureCredential
will authenticate as that user.Connect-AzAccount
command, DefaultAzureCredential
will authenticate as that user.azd auth login
command, the DefaultAzureCredential
will authenticate with that account.DefaultAzureCredential
will interactively authenticate a user via the default browser. This credential type is disabled by default.As of version 1.14.0, DefaultAzureCredential
will attempt to authenticate with all developer credentials until one succeeds, regardless of any errors previous developer credentials experienced. For example, a developer credential may attempt to get a token and fail, so DefaultAzureCredential
will continue to the next credential in the flow. Deployed service credentials will stop the flow with a thrown exception if they're able to attempt token retrieval, but don't receive one. Prior to version 1.14.0, developer credentials would similarly stop the authentication flow if token retrieval failed, but this is no longer the case.
This allows for trying all of the developer credentials on your machine while having predictable deployed behavior.
VisualStudioCodeCredential
Due to a known issue, VisualStudioCodeCredential
has been removed from the DefaultAzureCredential
token chain. When the issue is resolved in a future release, this change will be reverted.
The following examples are provided below:
DefaultAzureCredential
More details on configuring your environment to use the DefaultAzureCredential
can be found in the class's reference documentation.
This example demonstrates authenticating the BlobServiceClient
from the azure-storage-blob library using DefaultAzureCredential
.
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
default_credential = DefaultAzureCredential()
client = BlobServiceClient(account_url, credential=default_credential)
DefaultAzureCredential
Interactive authentication is disabled in the DefaultAzureCredential
by default and can be enabled with a keyword argument:
DefaultAzureCredential(exclude_interactive_browser_credential=False)
When enabled, DefaultAzureCredential
falls back to interactively authenticating via the system's default web browser when no other credential is available.
DefaultAzureCredential
Many Azure hosts allow the assignment of a user-assigned managed identity. To configure DefaultAzureCredential
to authenticate a user-assigned identity, use the managed_identity_client_id
keyword argument:
DefaultAzureCredential(managed_identity_client_id=client_id)
Alternatively, set the environment variable AZURE_CLIENT_ID
to the identity's client ID.
ChainedTokenCredential
DefaultAzureCredential
is generally the quickest way to get started developing applications for Azure. For more advanced scenarios, ChainedTokenCredential links multiple credential instances to be tried sequentially when authenticating. It will try each chained credential in turn until one provides a token or fails to authenticate due to an error.
The following example demonstrates creating a credential that will first attempt to authenticate using managed identity. The credential will fall back to authenticating via the Azure CLI when a managed identity is unavailable. This example uses the EventHubProducerClient
from the azure-eventhub client library.
from azure.eventhub import EventHubProducerClient
from azure.identity import AzureCliCredential, ChainedTokenCredential, ManagedIdentityCredential
managed_identity = ManagedIdentityCredential()
azure_cli = AzureCliCredential()
credential_chain = ChainedTokenCredential(managed_identity, azure_cli)
client = EventHubProducerClient(namespace, eventhub_name, credential_chain)
This library includes a set of async APIs. To use the async credentials in azure.identity.aio, you must first install an async transport, such as aiohttp. For more information, see azure-core documentation.
Async credentials should be closed when they're no longer needed. Each async credential is an async context manager and defines an async close
method. For example:
from azure.identity.aio import DefaultAzureCredential
# call close when the credential is no longer needed
credential = DefaultAzureCredential()
...
await credential.close()
# alternatively, use the credential as an async context manager
credential = DefaultAzureCredential()
async with credential:
...
This example demonstrates authenticating the asynchronous SecretClient
from azure-keyvault-secrets with an asynchronous
credential.
from azure.identity.aio import DefaultAzureCredential
from azure.keyvault.secrets.aio import SecretClient
default_credential = DefaultAzureCredential()
client = SecretClient("https://my-vault.vault.azure.net", default_credential)
Managed identity authentication is supported via either the DefaultAzureCredential
or the ManagedIdentityCredential
directly for the following Azure services:
from azure.identity import ManagedIdentityCredential
from azure.keyvault.secrets import SecretClient
credential = ManagedIdentityCredential(client_id=managed_identity_client_id)
client = SecretClient("https://my-vault.vault.azure.net", credential)
from azure.identity import ManagedIdentityCredential
from azure.keyvault.secrets import SecretClient
credential = ManagedIdentityCredential()
client = SecretClient("https://my-vault.vault.azure.net", credential)
Credentials default to authenticating to the Microsoft Entra endpoint for Azure Public Cloud. To access resources in other clouds, such as Azure Government or a private cloud, configure credentials with the authority
argument. AzureAuthorityHosts defines authorities for well-known clouds:
from azure.identity import AzureAuthorityHosts
DefaultAzureCredential(authority=AzureAuthorityHosts.AZURE_GOVERNMENT)
If the authority for your cloud isn't listed in AzureAuthorityHosts
, you can explicitly specify its URL:
DefaultAzureCredential(authority="https://login.partner.microsoftonline.cn")
As an alternative to specifying the authority
argument, you can also set the AZURE_AUTHORITY_HOST
environment variable to the URL of your cloud's authority. This approach is useful when configuring multiple credentials to authenticate to the same cloud:
AZURE_AUTHORITY_HOST=https://login.partner.microsoftonline.cn
Not all credentials require this configuration. Credentials that authenticate through a development tool, such as AzureCliCredential
, use that tool's configuration. Similarly, VisualStudioCodeCredential
accepts an authority
argument but defaults to the authority matching VS Code's "Azure: Cloud" setting.
Credential | Usage |
---|---|
DefaultAzureCredential |
Provides a simplified authentication experience to quickly start developing applications run in Azure. |
ChainedTokenCredential |
Allows users to define custom authentication flows composing multiple credentials. |
EnvironmentCredential |
Authenticates a service principal or user via credential information specified in environment variables. |
ManagedIdentityCredential |
Authenticates the managed identity of an Azure resource. |
WorkloadIdentityCredential |
Supports Microsoft Entra Workload ID on Kubernetes. |
Credential | Usage | Reference |
---|---|---|
CertificateCredential |
Authenticates a service principal using a certificate. | Service principal authentication |
ClientAssertionCredential |
Authenticates a service principal using a signed client assertion. | |
ClientSecretCredential |
Authenticates a service principal using a secret. | Service principal authentication |
Credential | Usage | Reference |
---|---|---|
AuthorizationCodeCredential |
Authenticates a user with a previously obtained authorization code. | OAuth2 authentication code |
DeviceCodeCredential |
Interactively authenticates a user on devices with limited UI. | Device code authentication |
InteractiveBrowserCredential |
Interactively authenticates a user with the default system browser. | OAuth2 authentication code |
OnBehalfOfCredential |
Propagates the delegated user identity and permissions through the request chain. | On-behalf-of authentication |
UsernamePasswordCredential |
Authenticates a user with a username and password (doesn't support multi-factor authentication). | Username + password authentication |
Credential | Usage | Reference |
---|---|---|
AzureCliCredential |
Authenticates in a development environment with the Azure CLI. | Azure CLI authentication |
AzureDeveloperCliCredential |
Authenticates in a development environment with the Azure Developer CLI. | Azure Developer CLI Reference |
AzurePowerShellCredential |
Authenticates in a development environment with the Azure PowerShell. | Azure PowerShell authentication |
VisualStudioCodeCredential |
Authenticates as the user signed in to the Visual Studio Code Azure Account extension. | VS Code Azure Account extension |
DefaultAzureCredential and EnvironmentCredential can be configured with environment variables. Each type of authentication requires values for specific variables:
Variable name | Value |
---|---|
AZURE_CLIENT_ID |
ID of a Microsoft Entra application |
AZURE_TENANT_ID |
ID of the application's Microsoft Entra tenant |
AZURE_CLIENT_SECRET |
one of the application's client secrets |
Variable name | Value |
---|---|
AZURE_CLIENT_ID |
ID of a Microsoft Entra application |
AZURE_TENANT_ID |
ID of the application's Microsoft Entra tenant |
AZURE_CLIENT_CERTIFICATE_PATH |
path to a PEM or PKCS12 certificate file including private key |
AZURE_CLIENT_CERTIFICATE_PASSWORD |
password of the certificate file, if any |
Variable name | Value |
---|---|
AZURE_CLIENT_ID |
ID of a Microsoft Entra application |
AZURE_USERNAME |
a username (usually an email address) |
AZURE_PASSWORD |
that user's password |
Configuration is attempted in the above order. For example, if values for a client secret and certificate are both present, the client secret will be used.
As of version 1.14.0, accessing resources protected by Continuous Access Evaluation (CAE) is possible on a per-request basis. This behavior can be enabled by setting the enable_cae
keyword argument to True
in the credential's get_token
method. CAE isn't supported for developer and managed identity credentials.
Token caching is a feature provided by the Azure Identity library that allows apps to:
The Azure Identity library offers both in-memory and persistent disk caching. For more details, see the token caching documentation.
An authentication broker is an application that runs on a user’s machine and manages the authentication handshakes and token maintenance for connected accounts. Currently, only the Windows Web Account Manager (WAM) is supported. To enable support, use the azure-identity-broker
package. For details on authenticating using WAM, see the broker plugin documentation.
See the troubleshooting guide for details on how to diagnose various failure scenarios.
Credentials raise CredentialUnavailableError
when they're unable to attempt authentication because they lack required data or state. For example,
EnvironmentCredential will raise this exception when its configuration is incomplete.
Credentials raise azure.core.exceptions.ClientAuthenticationError
when they fail to authenticate. ClientAuthenticationError
has a message
attribute, which describes why authentication failed. When raised by DefaultAzureCredential
or ChainedTokenCredential
, the message collects error messages from each credential in the chain.
For more information on handling specific Microsoft Entra ID errors, see the Microsoft Entra ID error code documentation.
This library uses the standard logging library for logging. Credentials log basic information, including HTTP sessions (URLs, headers, etc.) at INFO level. These log entries don't contain authentication secrets.
Detailed DEBUG level logging, including request/response bodies and header values, isn't enabled by default. It can be enabled with the logging_enable
argument. For example:
credential = DefaultAzureCredential(logging_enable=True)
CAUTION: DEBUG level logs from credentials contain sensitive information. These logs must be protected to avoid compromising account security.
Client and management libraries listed on the Azure SDK release page that support Microsoft Entra authentication accept credentials from this library. You can learn more about using these libraries in their documentation, which is linked from the release page.
This library doesn't support Azure AD B2C.
For other open issues, refer to the library's GitHub repository.
If you encounter bugs or have suggestions, open an issue.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You'll only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
enable_support_logging
as a keyword argument to credentials using MSAL's PublicClientApplication
. This allows additional support logging which may contain PII. (#32135)These changes do not impact the API of stable versions such as 1.14.0. Only code written against a beta version such as 1.15.0b1 may be affected.
ManagedIdentityCredential
will now correctly retry when the instance metadata endpoint returns a 410 response. (#32200)enable_msa_passthrough
suppport for InteractiveBrowserCredential
. By default InteractiveBrowserCredential
only lists Microsoft Entra accounts. If you set enable_msa_passthrough
to True
, it lists both Microsoft Entra accounts and MSA outlook.com accounts that are logged in to Windows.AzurePowershellCredential
calls PowerShell with the -NoProfile
flag to avoid loading user profiles for more consistent behavior. (#31682)ClientAssertionCredential
not properly checking if CAE should be enabled. (#31544)ManagedIdentityCredential
will fall through to the next credential in the chain in the case that Docker Desktop returns a 403 response when attempting to access the IMDS endpoint. (#31824)AsyncTokenCredential
protocol.DefaultAzureCredential
, EnvironmentCredential
will now use log level INFO instead of WARNING to inform users of an incomplete environment configuration. (#31814)AzureCliCredential
and AzureDeveloperCliCredential
error checking when determining if a user is logged in or not. Now, if an AADSTS
error exists in the error, the full error message is propagated instead of a canned error message. (#30047)ManagedIdentityCredential
instances using IMDS will now be allowed to continue sending requests to the IMDS endpoint even after previous attempts failed. This is to prevent credential instances from potentially being permanently disabled after a temporary network failure.ManagedIdentityCredential
will now only occur when inside a credential chain such as DefaultAzureCredential
. This probe request timeout has been increased to 1 second from 0.3 seconds to reduce the likelihood of false negatives.enable_cae
keyword argument to True
in get_token
. This applies to user credentials and service principal credentials. (#30777)get_token
request by each SDK. (#30777)
AZURE_IDENTITY_DISABLE_CP1
environment variable is no longer supported.azure-core
's TokenCredential
protocol. (#25175)workload_identity_tenant_id
support in DefaultAzureCredential
.six
. (#30613)These changes do not impact the API of stable versions such as 1.12.0. Only code written against a beta version such as 1.13.0b4 may be affected.
developer_credential_timeout
to process_timeout
in DefaultAzureCredential
to remain consistent with the other credentials that launch a subprocess to acquire tokens.process_timeout
keyword argument. This addresses scenarios where these proceses can take longer than the current default timeout values. The affected credentials are AzureCliCredential
, AzureDeveloperCliCredential
, and AzurePowerShellCredential
. (Note: For DefaultAzureCredential
, the developer_credential_timeout
keyword argument allows users to propagate this option to AzureCliCredential
, AzureDeveloperCliCredential
, and AzurePowerShellCredential
in the authentication chain.) (#28290)instance_discovery
to disable_instance_discovery
to make it more explicit.AzureDeveloperCredential
for Azure Developer CLI. (#27916)WorkloadIdentityCredential
for Workload Identity Federation on Kubernetes (#28536)AZURE_REGIONAL_AUTHORITY_NAME
to enable auto detecting the appropriate authority (#526)These changes do not impact the API of stable versions such as 1.12.0. Only code written against a beta version such as 1.12.0b1 may be affected.
validate_authority
with instance_discovery
. Now instead of setting validate_authority=False to disable authority validation and instance discovery, you need to use instance_discovery=False.AzureCliCredential
would return the wrong error message when the Azure CLI was not installed on non-English consoles. (#27965)AzureCliCredential
now works even when az
prints warnings to stderr. (#26857) (thanks to @micromaomao for the contribution)TokenCachePersistenceOptions
weren't propagated when using SharedTokenCacheCredential
(#26982)VisualStudioCodeCredential
from DefaultAzureCredential
token chain by default as SDK
authentication via Visual Studio Code is broken due to
issue #23249. The VisualStudioCodeCredential
will be
re-enabled in the DefaultAzureCredential
flow once a fix is in place.
Issue #25713 tracks this. In the meantime
Visual Studio Code users can authenticate their development environment using the Azure CLI.1.12.0 release candidate
tenant_id
for AzureCliCredential
& AzurePowerShellCredential
(thanks @tikicoder) (#25207)VisualStudioCodeCredential
from DefaultAzureCredential
token chain. (#23249)EnvironmentCredential
added AZURE_CLIENT_CERTIFICATE_PASSWORD
support for the cert password (#24652)validate_authority
support for msal client (#22625)additionally_allowed_tenants
to the following credential options to force explicit opt-in behavior for multi-tenant authentication:
AuthorizationCodeCredential
AzureCliCredential
AzurePowerShellCredential
CertificateCredential
ClientAssertionCredential
ClientSecretCredential
DefaultAzureCredential
OnBehalfOfCredential
UsernamePasswordCredential
VisualStudioCodeCredential
ClientAuthenticationError
if the requested tenant ID doesn't match the credential's tenant ID, and is not included in additionally_allowed_tenants
. Applications must now explicitly add additional tenants to the additionally_allowed_tenants
list, or add '*' to list, to enable acquiring tokens from tenants other than the originally specified tenant ID.More information on this change and the consideration behind it can be found here.
tenant_id
for AzureCliCredential
VisualStudioCodeCredential
from DefaultAzureCredential
token chainAZURE_CLIENT_CERTIFICATE_PASSWORD
support for EnvironmentCredential
validate_authority
supportAzure-identity is supported on Python 3.7 or later. For more details, please read our page on Azure SDK for Python version support policy.
tenant_id
for AzureCliCredential
(thanks @tikicoder) (#25207)VisualStudioCodeCredential
from DefaultAzureCredential
token chain. (#23249)EnvironmentCredential
added AZURE_CLIENT_CERTIFICATE_PASSWORD
support for the cert password (#24652)validate_authority
support for msal client (#22625)These changes do not impact the API of stable versions such as 1.9.0. Only code written against a beta version such as 1.10.0b1 may be affected.
validate_authority
support is not available in 1.10.0.validate_authority
support for msal client (#22625)These changes do not impact the API of stable versions such as 1.8.0. Only code written against a beta version such as 1.9.0b1 may be affected.
validate_authority
support is not available in 1.9.0.content
from msal response. (#23483)resource_id
, please use identity_config
instead.get_assertion
to func
for ClientAssertionCredential
.validate_authority
support for msal client (#22625)resource_id
support for user-assigned managed identity (#22329)ClientAssertionCredential
support (#22328)Handle injected "tenant_id" and "claims" (#23138)
"tenant_id" argument in get_token() method is only supported by:
AuthorizationCodeCredential
AzureCliCredential
AzurePowerShellCredential
InteractiveBrowserCredential
DeviceCodeCredential
EnvironmentCredential
UsernamePasswordCredential
it is ignored by other types of credentials.
These changes do not impact the API of stable versions such as 1.6.0. Only code written against a beta version such as 1.7.0b1 may be affected.
allow_multitenant_authentication
argument has been removed and the default behavior is now as if it were true.
The multitenant authentication feature can be totally disabled by setting the environment variable
AZURE_IDENTITY_DISABLE_MULTITENANTAUTH
to True
.azure.identity.RegionalAuthority
is removed.regional_authority
argument is removed for CertificateCredential
and ClientSecretCredential
.AzureApplicationCredential
is removed.client_credential
in the ctor of OnBehalfOfCredential
is removed. Please use client_secret
or client_certificate
instead.user_assertion
in the ctor of OnBehalfOfCredential
a keyword only argument.CertificateCredential
accepts certificates in PKCS12 format
(#13540)OnBehalfOfCredential
supports the on-behalf-of authentication flow for
accessing resources on behalf of users
(#19308)DefaultAzureCredential
allows specifying the client ID of interactive browser via keyword argument interactive_browser_client_id
(#20487)close()
to credentials in the
azure.identity
namespace. At the end of a with
block, or when close()
is called, these credentials close their underlying transport sessions.
(#18798)These changes do not impact the API of stable versions such as 1.6.0. Only code written against a beta version such as 1.7.0b1 may be affected.
AZURE_POD_IDENTITY_TOKEN_URL
to AZURE_POD_IDENTITY_AUTHORITY_HOST
.
The value should now be a host, for example "http://169.254.169.254" (the
default).azure.identity.aio.AzureApplicationCredential
(#19943)CustomHookPolicy
to credential HTTP pipelines. This allows applications
to initialize credentials with raw_request_hook
and raw_response_hook
keyword arguments. The value of these arguments should be a callback taking a
PipelineRequest
and PipelineResponse
, respectively. For example:
ManagedIdentityCredential(raw_request_hook=lambda request: print(request.http_request.url))
ChainedTokenCredential
and DefaultAzureCredential
logging. On Python 3.7+, credentials invoked by these classes now log debug
rather than info messages.
(#18972)InteractiveBrowserCredential
keyword argument login_hint
enables
pre-filling the username/email address field on the login page
(#19225)AzureApplicationCredential
, a default credential chain for applications
deployed to Azure
(#19309)azure.identity.aio.ManagedIdentityCredential
is an async context manager
that closes its underlying transport session at the end of a with
blockallow_multitenant_authentication
.
(#19300)
allow_multitenant_authentication
is False, which is the default, a
credential will raise ClientAuthenticationError
when its configured tenant
doesn't match the tenant specified for a token request. This may be a
different exception than was raised by prior versions of the credential. To
maintain the prior behavior, set environment variable
AZURE_IDENTITY_ENABLE_LEGACY_TENANT_SELECTION to "True".CertificateCredential
and ClientSecretCredential
support regional STS
on Azure VMs by either keyword argument regional_authority
or environment
variable AZURE_REGIONAL_AUTHORITY_NAME
. See azure.identity.RegionalAuthority
for possible values.
(#19301)azure-core
version to 1.11.0 and minimum msal
version to
1.12.0ManagedIdentityCredential
raises consistent
error messages and uses raise from
to propagate inner exceptions
(#19423)Beginning with this release, this library requires Python 2.7 or 3.6+.
VisualStudioCodeCredential
gets its default tenant and authority
configuration from VS Code user settings
(#14808)This is the last version to support Python 3.5. The next version will require Python 2.7 or 3.6+.
AzurePowerShellCredential
authenticates as the identity logged in to Azure
PowerShell. This credential is part of DefaultAzureCredential
by default
but can be disabled by a keyword argument:
DefaultAzureCredential(exclude_powershell_credential=True)
(#17341)AzureCliCredential
raises CredentialUnavailableError
when the CLI times out,
and kills timed out subprocessesManagedIdentityCredential
on Azure VMsThese changes do not impact the API of stable versions such as 1.5.0. Only code written against a beta version such as 1.6.0b1 may be affected.
AuthenticationRequiredError.error_details
InteractiveBrowserCredential
functions in more WSL environments
(#17615)These changes do not impact the API of stable versions such as 1.5.0. Only code written against a beta version such as 1.6.0b1 may be affected.
Renamed CertificateCredential
keyword argument certificate_bytes
to
certificate_data
Credentials accepting keyword arguments allow_unencrypted_cache
and
enable_persistent_cache
to configure persistent caching accept a
cache_persistence_options
argument instead whose value should be an
instance of TokenCachePersistenceOptions
. For example:
# before (e.g. in 1.6.0b1):
DeviceCodeCredential(enable_persistent_cache=True, allow_unencrypted_cache=True)
# after:
cache_options = TokenCachePersistenceOptions(allow_unencrypted_storage=True)
DeviceCodeCredential(cache_persistence_options=cache_options)
See the documentation and samples for more details.
TokenCachePersistenceOptions
configures persistent cachingAuthenticationRequiredError.claims
property provides any additional
claims required by a user credential's authenticate()
methodInteractiveBrowserCredential
uses PKCE internally to protect authorization
codesCertificateCredential
can load a certificate from bytes instead of a file
path. To provide a certificate as bytes, use the keyword argument
certificate_bytes
instead of certificate_path
, for example:
CertificateCredential(tenant_id, client_id, certificate_bytes=cert_bytes)
(#14055)ManagedIdentityCredential
correctly parses responses from the current
(preview) version of Azure ML managed identity
(#15361)CertificateCredential
keyword argument send_certificate
(added in 1.5.0b1) to send_certificate_chain
authenticate
method from DeviceCodeCredential
,
InteractiveBrowserCredential
, and UsernamePasswordCredential
allow_unencrypted_cache
and enable_persistent_cache
keyword
arguments from CertificateCredential
, ClientSecretCredential
,
DeviceCodeCredential
, InteractiveBrowserCredential
, and
UsernamePasswordCredential
disable_automatic_authentication
keyword argument from
DeviceCodeCredential
and InteractiveBrowserCredential
allow_unencrypted_cache
keyword argument from
SharedTokenCacheCredential
AuthenticationRecord
and AuthenticationRequiredError
identity_config
keyword argument from ManagedIdentityCredential
(was added in 1.5.0b1)DeviceCodeCredential
parameter client_id
is now optional. When not
provided, the credential will authenticate users to an Azure development
application.
(#14354)ValueError
when constructed with tenant IDs containing
invalid characters
(#14821)VisualStudioCodeCredential
using invalid authentication data when
no user is signed in to Visual Studio Code
(#14438)ManagedIdentityCredential
uses the API version supported by Azure Functions
on Linux consumption hosting plans
(#14670)InteractiveBrowserCredential.get_token()
raises a clearer error message when
it times out waiting for a user to authenticate on Python 2.7
(#14773)AzureCliCredential.get_token
correctly sets token expiration time,
preventing clients from using expired tokens
(#14345)AzureCliCredential.get_token
correctly sets token expiration time,
preventing clients from using expired tokens
(#14345)ManagedIdentityCredential
supports the latest version of App Service
(#11346)DefaultAzureCredential
allows specifying the client ID of a user-assigned
managed identity via keyword argument managed_identity_client_id
(#12991)CertificateCredential
supports Subject Name/Issuer authentication when
created with send_certificate=True
. The async CertificateCredential
(azure.identity.aio.CertificateCredential
) will support this in a
future version.
(#10816)azure.identity
support ADFS authorities, excepting
VisualStudioCodeCredential
. To configure a credential for this, configure
the credential with authority
and tenant_id="adfs"
keyword arguments, for
example
ClientSecretCredential(authority="<your ADFS URI>", tenant_id="adfs")
.
Async credentials (those in azure.identity.aio
) will support ADFS in a
future release.
(#12696)InteractiveBrowserCredential
keyword argument redirect_uri
enables
authentication with a user-specified application having a custom redirect URI
(#13344)authentication_record
keyword argument from the async
SharedTokenCacheCredential
, i.e. azure.identity.aio.SharedTokenCacheCredential
DefaultAzureCredential
uses the value of environment variable
AZURE_CLIENT_ID
to configure a user-assigned managed identity.
(#10931)VSCodeCredential
to VisualStudioCodeCredential
authenticate
method from DeviceCodeCredential
,
InteractiveBrowserCredential
, and UsernamePasswordCredential
allow_unencrypted_cache
and enable_persistent_cache
keyword
arguments from CertificateCredential
, ClientSecretCredential
,
DeviceCodeCredential
, InteractiveBrowserCredential
, and
UsernamePasswordCredential
disable_automatic_authentication
keyword argument from
DeviceCodeCredential
and InteractiveBrowserCredential
allow_unencrypted_cache
keyword argument from
SharedTokenCacheCredential
AuthenticationRecord
and AuthenticationRequiredError
identity_config
keyword argument from ManagedIdentityCredential
DefaultAzureCredential
has a new optional keyword argument,
visual_studio_code_tenant_id
, which sets the tenant the credential should
authenticate in when authenticating as the Azure user signed in to Visual
Studio Code.AuthenticationRecord.deserialize
positional parameter json_string
to data
.AzureCliCredential
no longer raises an exception due to unexpected output
from the CLI when run by PyCharm (thanks @NVolcz)
(#11362)msal
version to 1.3.0AzureCliCredential
correctly invokes /bin/sh
(#12048)AzureCliCredential
on Windows caused by a bug
in old versions of Python 3.6 (this bug was fixed in Python 3.6.5).
(#12014)SharedTokenCacheCredential.get_token
raises ValueError
instead of
ClientAuthenticationError
when called with no scopes.
(#11553)ManagedIdentityCredential
can configure a user-assigned identity using any
identifier supported by the current hosting environment. To specify an
identity by its client ID, continue using the client_id
argument. To
specify an identity by any other ID, use the identity_config
argument,
for example: ManagedIdentityCredential(identity_config={"object_id": ".."})
(#10989)CertificateCredential
and ClientSecretCredential
can optionally store
access tokens they acquire in a persistent cache. To enable this, construct
the credential with enable_persistent_cache=True
. On Linux, the persistent
cache requires libsecret and pygobject
. If these are unavailable or
unusable (e.g. in an SSH session), loading the persistent cache will raise an
error. You may optionally configure the credential to fall back to an
unencrypted cache by constructing it with keyword argument
allow_unencrypted_cache=True
.
(#11347)AzureCliCredential
raises CredentialUnavailableError
when no user is
logged in to the Azure CLI.
(#11819)AzureCliCredential
and VSCodeCredential
, which enable authenticating as
the identity signed in to the Azure CLI and Visual Studio Code, respectively,
can be imported from azure.identity
and azure.identity.aio
.azure.identity.aio.AuthorizationCodeCredential.get_token()
no longer accepts
optional keyword arguments executor
or loop
. Prior versions of the method
didn't use these correctly, provoking exceptions, and internal changes in this
version have made them obsolete.InteractiveBrowserCredential
raises CredentialUnavailableError
when it
can't start an HTTP server on localhost
.
(#11665)DefaultAzureCredential
, you can now configure a tenant ID
for InteractiveBrowserCredential
. When none is specified, the credential
authenticates users in their home tenants. To specify a different tenant, use
the keyword argument interactive_browser_tenant_id
, or set the environment
variable AZURE_TENANT_ID
.
(#11548)SharedTokenCacheCredential
can be initialized with an AuthenticationRecord
provided by a user credential.
(#11448)DeviceCodeCredential
and
InteractiveBrowserCredential
in 1.4.0b3 is available on
UsernamePasswordCredential
as well.
(#11449)DeviceCodeCredential
and
InteractiveBrowserCredential
added in 1.4.0b3 is now available on Linux and
macOS as well as Windows.
(#11134)
pygobject
. If these
are unavailable, or libsecret is unusable (e.g. in an SSH session), loading
the persistent cache will raise an error. You may optionally configure the
credential to fall back to an unencrypted cache by constructing it with
keyword argument allow_unencrypted_cache=True
.EnvironmentCredential
correctly initializes UsernamePasswordCredential
with the value of AZURE_TENANT_ID
(#11127)authority
and
AZURE_AUTHORITY_HOST
may optionally specify an "https" scheme. For example,
"https://login.microsoftonline.us" and "login.microsoftonline.us" are both valid.
(#10819)DeviceCodeCredential
and InteractiveBrowserCredential
(#10612)
authenticate
interactively authenticates a user, returns a
serializable AuthenticationRecord
authentication_record
enables initializing a credential with an
AuthenticationRecord
from a prior authenticationdisable_automatic_authentication=True
configures the credential to raise
AuthenticationRequiredError
when interactive authentication is necessary
to acquire a token rather than immediately begin that authenticationenable_persistent_cache=True
configures these credentials to use a
persistent cache on supported platforms (in this release, Windows only).
By default they cache in memory only.DefaultAzureCredential
can authenticate with the identity signed in to
Visual Studio Code's Azure extension.
(#10472)DefaultAzureCredential
successfully authenticates, it
uses the same authentication method for every subsequent token request. This
makes subsequent requests more efficient, and prevents unexpected changes of
authentication method.
(#10349)get_token
methods consistently require at least one scope argument,
raising an error when none is passed. Although get_token()
may sometimes
have succeeded in prior versions, it couldn't do so consistently because its
behavior was undefined, and dependened on the credential's type and internal
state. (#10243)SharedTokenCacheCredential
raises CredentialUnavailableError
when the
cache is available but contains ambiguous or insufficient information. This
causes ChainedTokenCredential
to correctly try the next credential in the
chain. (#10631)AZURE_AUTHORITY_HOST
. See
azure.identity.KnownAuthorities
for a list of common values.
(#8094)ManagedIdentityCredential
raises CredentialUnavailableError
when no
identity is configured for an IMDS endpoint. This causes
ChainedTokenCredential
to correctly try the next credential in the chain.
(#10488)DefaultAzureCredential
can now authenticate using the identity logged in to
the Azure CLI, unless explicitly disabled with a keyword argument:
DefaultAzureCredential(exclude_cli_credential=True)
(#10092)CredentialUnavailableError
when they can't attempt to
authenticate due to missing data or state
(#9372)CertificateCredential
supports password-protected private keys
(#9434)ProxyPolicy
(#8945)close
method
(#9090)DefaultAzureCredential
no longer raises ImportError
on Python
3.8 on Windows (8294)InteractiveBrowserCredential
raises when unable to open a web browser
(8465)InteractiveBrowserCredential
prompts for account selection
(8470)DefaultAzureCredential
are configurable by keyword
arguments (8514)SharedTokenCacheCredential
accepts an optional tenant_id
keyword argument
(8689)ClientCertificateCredential
uses application and tenant IDs correctly
(8315)InteractiveBrowserCredential
properly caches tokens
(8352)aiohttp
for transport but the library does not require it as a dependency because the
async API is optional. To use async credentials, please install
aiohttp
or see
azure-core documentation
for information about customizing the transport.ClientSecretCredential
parameter "secret
" to "client_secret
"tenant_id
and client_id
positional parameters now accept them in that orderInteractiveBrowserCredential
parameters
client_id
is now an optional keyword argument. If no value is provided,
the Azure CLI's client ID will be used.tenant
renamed tenant_id
DeviceCodeCredential
prompt_callback
is now a keyword argumentprompt_callback
's third argument is now a datetime
representing the
expiration time of the device codetenant
renamed tenant_id
ManagedIdentityCredential
client_id
azure-core
documentationDefaultAzureCredential
accepts an authority
keyword argument, enabling
its use in national clouds
(#8154)msal_extensions
0.1.2msal
requirement to >=0.4.1,
<1.0.0AuthorizationCodeCredential
authenticates with a previously obtained
authorization code. See Microsoft Entra's
authorization code documentation
for more information about this authentication flow.authority
keyword argument. Known
authorities are defined in azure.identity.KnownAuthorities
. The default
authority is for Azure Public Cloud, login.microsoftonline.com
(KnownAuthorities.AZURE_PUBLIC_CLOUD
). An application running in Azure
Government would use KnownAuthorities.AZURE_GOVERNMENT
instead:from azure.identity import DefaultAzureCredential, KnownAuthorities credential = DefaultAzureCredential(authority=KnownAuthorities.AZURE_GOVERNMENT)
client_secret
parameter from InteractiveBrowserCredential
UsernamePasswordCredential
correctly handles environment configuration with
no tenant information (#7260)SharedTokenCacheCredential
authenticates with tokens stored in a local
cache shared by Microsoft applications. This enables Azure SDK clients to
authenticate silently after you've signed in to Visual Studio 2019, for
example. DefaultAzureCredential
includes SharedTokenCacheCredential
when
the shared cache is available, and environment variable AZURE_USERNAME
is set. See the
README
for more information.msal-extensions
0.1.1azure.core.Configuration
from the public API in preparation for a
revamped configuration API. Static create_config
methods have been renamed
_create_config
, and will be removed in a future release.pip install azure-core==1.0.0b1 azure-identity==1.0.0b1
DeviceCodeCredential
InteractiveBrowserCredential
UsernamePasswordCredential
Version 1.0.0b1 is the first preview of our efforts to create a user-friendly and Pythonic authentication API for Azure SDK client libraries. For more information about preview releases of other Azure SDK libraries, please visit https://aka.ms/azure-sdk-preview1-python.
This release supports service principal and managed identity authentication. See the documentation for more details. User authentication will be added in an upcoming preview release.
This release supports only global Microsoft Entra tenants, i.e. those using the https://login.microsoftonline.com authentication endpoint.