🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › azure-identity › azure.identity.defaultazurecredential
azure.identity.DefaultAzureCredential class | Microsoft Learn
... Request an access token for scopes. This method is called automatically by Azure SDK clients. get_token(*scopes: str, claims: str | None = None, tenant_id: str | None = None, **kwargs: Any) -> AccessToken
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › azure-identity › azure.identity.aio.defaultazurecredential
azure.identity.aio.DefaultAzureCredential class | Microsoft Learn
... Asynchronously request an access token for scopes. This method is called automatically by Azure SDK clients. async get_token(*scopes: str, claims: str | None = None, tenant_id: str | None = None, **kwargs: Any) -> AccessToken
Discussions

python 3.x - How to properly use "get_token" of "ManagedIdentityCredential" of azure identity - Stack Overflow
I am trying to use managed identity of Azure function to access AAD protected web app, which requires a custom flow instead of using different clients. So the first step is to obtain an access token: More on stackoverflow.com
🌐 stackoverflow.com
Generate longer token for Databricks with Azure.
Is there a way to get a longer token for databricks with a Service Principal ? Since this aim to be for production, I wish my code could generate a PAT for any run, I don't want to create a PAT manually and store it to an Azure Key Vault. ... I made up an alternative solution. I made up my own python class to handle my PAT from Databricks : https://stackoverflow.com/questions/75071869/python-defaultazurecredential... More on community.databricks.com
🌐 community.databricks.com
2
1
January 16, 2023
python - How to get bearer token from Azure SDK DefaultCredential - Stack Overflow
Problem : I need to get a list of certificates of apps registered under Azure AD and renew the ones which are expiring. I was able to get the apps related details through Microsoft Graph API > More on stackoverflow.com
🌐 stackoverflow.com
Python azure-identity ClientSecretCredential - Stack Overflow
I’m trying to get an access token via the azure-identity python package for accessing an Azure Service. I done the app registration in the Azure AD and I got the following C# code, which works as More on stackoverflow.com
🌐 stackoverflow.com
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › developer › python › sdk › authentication › credential-chains
Credential chains in the Azure Identity library for Python - Python on Azure | Microsoft Learn
January 15, 2026 - The AzureCliCredential.get_token call succeeds and the output also indicates that DefaultAzureCredential acquired a token from AzureCliCredential. Since AzureCliCredential succeeded, no credentials beyond it were tried. ... In the preceding example, the logging level is set to logging.DEBUG.
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › overview › azure › identity-readme
Azure Identity client library for Python | Microsoft Learn
As of version 1.14.0, ... 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....
🌐
PyPI
pypi.org › project › azure-identity
azure-identity · PyPI
1 week ago - As of version 1.14.0, ... 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....
🌐
Neural Flow
danielscottraynsford.com › blog › using-azuredefaultcredential-with-semantic-kernel-in-python
Using AzureDefaultCredential with Semantic Kernel in Python
May 17, 2025 - To do this, I needed to use the ... from the Semantic Kernel Python SDK. from azure.identity import DefaultAzureCredential, get_bearer_token_provider import semantic_kernel as sk ......
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › azure-core › azure.core.credentials.tokencredential
azure.core.credentials.TokenCredential class | Microsoft Learn
Request an access token for scopes. get_token(*scopes: str, claims: str | None = None, tenant_id: str | None = None, enable_cae: bool = False, **kwargs: Any) -> AccessToken
🌐
Medium
gabrielgomes61320.medium.com › microsoft-identity-library-deep-dive-e79c5d38109c
Microsoft Identity library Deep Dive | by Gabriel Gomes, PhD | Medium
December 18, 2023 - The default.py file contains the DefaultAzureCredential Class, with two methods inside it: the standard __init__ method (which is an instance method that initializes a newly created object), and the get_token method. The first method contains all the logic for the chained credentials setup.
Find elsewhere
🌐
OneUptime
oneuptime.com › home › blog › how to authenticate with azure services using azure-identity
How to Authenticate with Azure Services Using azure-identity
February 16, 2026 - On your development machine, DefaultAzureCredential typically uses your Azure CLI session. Make sure you are logged in first. # Log in to Azure CLI az login # Verify your account az account show · Once logged in, any Python script using DefaultAzureCredential will automatically use your CLI session.
🌐
Windows
azuresdkdocs.z19.web.core.windows.net › python › azure-identity › latest › azure.identity.html
azure.identity package — Azure SDK for Python 2.0.0 documentation
require_envvar (bool) – If True, require that the AZURE_TOKEN_CREDENTIALS environment variable be set to a value denoting the credential type or credential group to use. If unset or empty, DefaultAzureCredential will raise a ValueError. Defaults to False. ... Close the transport session of each credential in the chain. get_token(*scopes: str, claims: str | None = None, tenant_id: str | None = None, **kwargs: Any) → AccessToken[source]
🌐
Medium
medium.com › @oliverdevijt › why-defaultazurecredential-fails-after-az-login-tenant-and-how-to-fix-it-707ac747ace0
Why DefaultAzureCredential fails after az login --tenant (and how to fix it) | by Oliver De Vijt | Medium
April 16, 2025 - When initializing DefaultAzureCredential, you can permit it to acquire tokens for additional tenants:​ · pythonfrom azure.identity import DefaultAzureCredential credential = DefaultAzureCredential(additionally_allowed_tenants=["*"])
🌐
Thomas Stringer
trstringer.com › authenticate-python-to-azure
Authenticate to Azure from Python | Thomas Stringer
February 28, 2021 - One of the really great and easy things that was introduced in the Azure Python SDK is the DefaultAzureCredential helper class. It is a great single solution for all of your authentication requirements because it tries five different sources of authentication.
🌐
Databricks Community
community.databricks.com › databricks community › data engineering › generate longer token for databricks with azure.
Solved: Generate longer token for Databricks with Azure. - Databricks Community - 12614
January 16, 2023 - Every X minutes I ask for a new token, but I have to re init my sparksession and loose all the work. Isn"t a way to inject the token in spark.config ? ... I made up an alternative solution. I made up my own python class to handle my PAT from Databricks : https://stackoverflow.com/questions/75071869/python-defaultazurecredential-get-token-set-expiration-...
🌐
GitHub
github.com › Azure › azure-sdk-for-python › blob › main › sdk › identity › azure-identity › azure › identity › _credentials › default.py
azure-sdk-for-python/sdk/identity/azure-identity/azure/identity/_credentials/default.py at main · Azure/azure-sdk-for-python · GitHub
def get_token_info(self, *scopes, options: Optional[TokenRequestOptions] = None, **kwargs: Any) -> AccessTokenInfo: raise CredentialUnavailableError(self._error) ... """A credential capable of handling most Azure SDK authentication scenarios. For more information, See ... <"https://aka.ms/azsdk/python/identity/credential-chains#usage-guidance-for-defaultazurecredential">`__.
🌐
Windows
azuresdkdocs.z19.web.core.windows.net › python › azure-identity › latest › index.html
Azure Identity client library for Python — Azure SDK for Python 2.0.0 documentation
As of version 1.14.0, DefaultAzureCredential attempts 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 ...
🌐
MCP Servers
mcpservers.org › home › claude skills & agent skills library › azure-identity-py
azure-identity-py | Claude Skills & Agent Skills Library
Helper that wraps a credential into a callable returning a bearer token string. Essential for OpenAI SDK and other non-Azure-SDK clients: from azure.identity import DefaultAzureCredential, get_bearer_token_provider credential = DefaultAzureCredential() token_provider = get_bearer_token_provider( credential, "https://cognitiveservices.azure.com/.default" ) ...
🌐
Stack Overflow
stackoverflow.com › questions › 69615672 › how-to-get-bearer-token-from-azure-sdk-defaultcredential
python - How to get bearer token from Azure SDK DefaultCredential - Stack Overflow
I got some reference of Azure SDK ... Authorization · Code: from azure.identity import DefaultAzureCredential default_credential = DefaultAzureCredential() References: Azure api or sdk to get list of app registrations and the ...
Top answer
1 of 3
6

When I use the .net Microsoft.IdentityModel.Clients.ActiveDirectory library I don’t have to think about scope.

Actually, you have thought about it. When you use the code below via .net sdk, there is an aasUrl, this is the equivalent you need to specify in python sdk.

AuthenticationResult authenticationResult = await authContext.AcquireTokenAsync(aasUrl, clientCred);

With Microsoft.IdentityModel.Clients.ActiveDirectory, the method AcquireTokenAsync essentially uses the Azure AD client credential flow v1.0 endpoint to get the token, so this parameter is named as resource, i.e. the resource parameter in this method AcquireTokenAsync(String, ClientCredential).

In python sdk azure.identity, this method get_token essentially uses Azure AD client credential flow v2.0 endpoint to get the token, when v1.0 endpoint migrates to v2.0, there are some changes, one of them is the resource, it changed to scope, see this doc. When using scope, you need to specify the permission you want to access, you can also use /.default, then by default all the permissions added to the app will be requested.

So in your case, you just need to use the scope as aasUrl/.default, e.g. https://management.azure.com/.default, it depends on yourself.

token = credential.get_token("https://management.azure.com/.default")

Also have a test with the code on my side, it works fine.

2 of 3
0

if you are using Graph API you could use as

https://graph.microsoft.com/.default

https://graph.microsoft.com/Directory.Read

https://graph.microsoft.com/user_impersonation

if you are using Azure Resource Manager API then the base uri would be https://management.core.windows.net followed by the necessary permission.

If you want to acquire a token for all the static scopes of a v1.0 application, append ".default" to the app ID URI of the API

You Will see the APP Id uri in the Application Overview page

if you have not created app id uri, you set the uri and add permission scope