Hello @HASLEHNER, MYLENE

Thanks for reaching out to us.

The error message you received indicates that the Azure ML SDK was unable to retrieve a token from the included credentials. This can happen if the credentials you are using are invalid or if there is an issue with the authentication process.

To resolve this issue, you can try the following steps**:**

Check that you have the correct credentials for your Azure account. You can do this by logging into the Azure portal and checking the credentials for your account.

If you are using a service principal for authentication, make sure that the service principal has the correct permissions to access the resources you are trying to use.

Check that your environment variables are set correctly. You can set environment variables in the notebook by using the os module. For example, to set the AZURE_CLIENT_ID environment variable, you can use the following command:

import os
os.environ['AZURE_CLIENT_ID'] = ''

Replace with the actual client ID for your Azure account.

If you continue to experience issues, you may want to try using a different authentication method, such as interactive authentication or managed identity.

It's difficult to say exactly which commands in the notebook need to be written to avoid this error without seeing the notebook itself. However, you can try setting the environment variables as described above and see if that resolves the issue.

Let me know how it works. I am happy to help you further.

Regards,

Yutong

-Please kindly accept the answer and vote 'Yes' if you feel helpful to support the community, thanks a lot.

Answer from YutongTie-9091 on learn.microsoft.com
Top answer
1 of 3
2

Hello @HASLEHNER, MYLENE

Thanks for reaching out to us.

The error message you received indicates that the Azure ML SDK was unable to retrieve a token from the included credentials. This can happen if the credentials you are using are invalid or if there is an issue with the authentication process.

To resolve this issue, you can try the following steps**:**

Check that you have the correct credentials for your Azure account. You can do this by logging into the Azure portal and checking the credentials for your account.

If you are using a service principal for authentication, make sure that the service principal has the correct permissions to access the resources you are trying to use.

Check that your environment variables are set correctly. You can set environment variables in the notebook by using the os module. For example, to set the AZURE_CLIENT_ID environment variable, you can use the following command:

import os
os.environ['AZURE_CLIENT_ID'] = ''

Replace with the actual client ID for your Azure account.

If you continue to experience issues, you may want to try using a different authentication method, such as interactive authentication or managed identity.

It's difficult to say exactly which commands in the notebook need to be written to avoid this error without seeing the notebook itself. However, you can try setting the environment variables as described above and see if that resolves the issue.

Let me know how it works. I am happy to help you further.

Regards,

Yutong

-Please kindly accept the answer and vote 'Yes' if you feel helpful to support the community, thanks a lot.

2 of 3
1

Hi,

Thank you for you answer! I cannot find my client ID. The only thing I find is a

"tenant ID" in the folder Tenant details in Azure Active Directory. Is this the desired ID?

Thanks

🌐
Reddit
reddit.com › r/azure › how to solve 'defaultazurecredential failed to retrieve a token' error?
r/AZURE on Reddit: How to solve 'DefaultAzureCredential failed to retrieve a token' error?
November 7, 2024 -

Hi

I have deployed a docker image in my azure app service and I am using below code to connect my key vault:

credential = DefaultAzureCredential()
client = SecretClient(vault_url=KV_URI, credential=credential)
secret = client.get_secret(secret_name)

But I am getting this error:

ERROR:root:Error fetching secrets from key vault : DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot this issue.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
AzureCliCredential: Please run 'az login' to set up an account
AzurePowerShellCredential: PowerShell is not installed
AzureDeveloperCliCredential: Azure Developer CLI could not be found. Please visit  for installation instructions and then,once installed, authenticate to your Azure account using 'azd auth login'.https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoothttps://aka.ms/azure-dev

I have created a user assigned managed identity, assigned that UAMI to my app service, provided 'key vault secret user' access to that UAMI.

Also, the same code and access are working on QA environment but not on UAT so I am unable to find the core problem.

Can anyone please help me with this?

Thanks

🌐
Reddit
reddit.com › r/csharp › resolution to "[credentialunavailableexception: defaultazurecredential failed to retrieve a token from the included credentials." in visual studio when debugging using azure app authentication.
r/csharp on Reddit: Resolution to "[CredentialUnavailableException: DefaultAzureCredential failed to retrieve a token from the included credentials." in Visual Studio when debugging using Azure App Authentication.
May 27, 2020 -

I am posting this in the hopes that it helps someone with this frustrating issue.

If you are using Azure App Authentication in your .NET app to remove sensitive credentials from your web.config/app.config files, you may have run into this issue:

You start debugging your app and get the following exception:

[CredentialUnavailableException: DefaultAzureCredential failed to retrieve a token from the included credentials. EnvironmentCredential authentication unavailable. Environment variables are not fully configured. ManagedIdentityCredential authentication unavailable, no managed identity endpoint found. SharedTokenCacheCredential authentication unavailable. Token acquisition failed for user . Ensure that you have authenticated with a developer tool that supports Azure single sign on.]

Before pulling your hair out, try these steps:

  1. In Visual Studio, go to Tools -> Options

  2. Select "Account Selection" under "Azure Service Authentication"

  3. After selecting, you should see an area that says "Choose an account:" with a dropdown list of accounts you've used.

  4. (If you don't see "Reenter your credentials", go to Step #5) Right under this box, if you see "Reenter your credentials", click the link and follow the prompts. You should end up back on the same screen when you're done and the message should be gone.

  5. Click the dropdown, revealing the menu with a list of accounts and a button "Add an account...".

  6. Click "Add an account..."

  7. In the next pop-up, select "Use another account", even if you see the account you want to use in the list.

  8. Enter the email address & credentials of your account like normal and authenticate.

  9. Click "OK" and attempt to debug again.

The issue seems to be related to 2FA when enabled in your Azure tenant. If you do not have 2FA enabled (you should...), you may not have this problem.

I spent countless hours trying to resolve this issue and it seemed completely random when this error would occur (I believe it's when the 2FA token expires and fails to automatically request a new token). I hope this helps someone else and saves a few hours of frustration. :)

PS - If you are on Step #4 and you can see the "Reenter your credentials" link, but when clicking it, nothing happens... go to Step #5 and complete to Step #8. After this, click the "Reenter..." link again and it should work, prompting you for your account information again. Follow these prompts and you're done.

🌐
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 - This occurs because, starting with Azure Identity library version 1.11.0, credentials are restricted from acquiring tokens for tenants other than the one they’re configured for, unless explicitly permitted.​ · For instance, if you’ve authenticated to Tenant B using Azure CLI (az login --tenant <tenant-id>), but your DefaultAzureCredential is initialized without specifying Tenant B, the library will block token requests for Tenant B by default.
🌐
GitHub
github.com › Azure › azure-sdk-for-python › issues › 29040
ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials. · Issue #29040 · Azure/azure-sdk-for-python · GitHub
February 27, 2023 - I tried, to do az upgrade, az login, clear cache in .azure folder under C://Users/; but DefaultAzureCredential() didn't work. It was still taking stale token.
Author: Azure
🌐
.net dev life
dotnetdevlife.wordpress.com › 2022 › 02 › 07 › steps-to-resolve-defaultazurecredential-failed-to-retrieve-a-token-error
Steps to resolve “DefaultAzureCredential failed to retrieve a token” error – .net dev life
July 14, 2022 - Azure.Identity.CredentialUnavailableException HResult=0x80131500 Message=DefaultAzureCredential failed to retrieve a token from the included credentials. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/defaultazurecredential/troubleshoot - EnvironmentCredential authentication unavailable.
🌐
Microsoft Community Hub
techcommunity.microsoft.com › microsoft community hub › communities › products › microsoft iis › iis support blog
DefaultAzureCredential failed to retrieve a token
November 9, 2023 - If you try to retrieve a value from Azure Key Vault, you may run into this error: “DefaultAzureCredential failed to retrieve a token from the included credentials”.
Find elsewhere
🌐
Databricks Community
community.databricks.com › databricks community › data engineering › job is failing with exception clientauthenticationerror: defaultazurecredential failed to retrieve a token from the included credentials.
Job is failing with exception ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials.
July 12, 2022 - ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials. Attempted credentials: EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. Visit https://aka.ms/azsdk/python/identity/envir...
🌐
Brainly
brainly.com › computers and technology › high school › defaultazurecredential failed to retrieve a token from the included credentials.
[FREE] DefaultAzureCredential failed to retrieve a token from the included credentials. - brainly.com
November 19, 2023 - The error message "DefaultAzureCredential failed to retrieve a token from the included credentials" is an indication that the Azure SDK is unable to authenticate successfully using the defined credentials.
🌐
GitHub
github.com › Azure › azure-sdk-for-net › issues › 18782
DefaultAzureCredential failed to retrieve a token from the included credentials [BUG] · Issue #18782 · Azure/azure-sdk-for-net · GitHub
February 16, 2021 - // // Parameters: // options: // Options that configure the management of the requests sent to Azure Active Directory // services, and determine which credentials are included in the Azure.Identity.DefaultAzureCredential // authentication flow. public DefaultAzureCredential(DefaultAzureCredentialOptions options); // // Summary: // Sequentially calls Azure.Core.TokenCredential.GetToken(Azure.Core.TokenRequestContext,System.Threading.CancellationToken) // on all the included credentials in the order Azure.Identity.EnvironmentCredential, // Azure.Identity.ManagedIdentityCredential, Azure.Identity.SharedTokenCacheCredential, // and Azure.Identity.InteractiveBrowserCredential returning the first successfully // obtained Azure.Core.AccessToken.
Author: Azure
🌐
Stack Overflow
stackoverflow.com › questions › 79833430 › defaultazurecredential-failed-to-retrieve-a-token-from-the-included-credentials
azure - DefaultAzureCredential failed to retrieve a token from the included credentials - Stack Overflow
See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/brokercredential/troubleshoot) Inner Exception 2: CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot DefaultAzureCredential failed to retrieve a token from the included credentials.
Top answer
1 of 1
2

Refer this SO answer by Dasari Kamali. For retrieving secret value in Azure Function via Visual Studio.

I agree with Gaurav Mantri try implementing : var credential = new DefaultAzureCredential(); in your code:-

My user who is logged in to Visual Studio with PowerShell terminal and Profile having Key vault administrator role assigned at the Key vault level like below: -

I have enabled RBAC based access for Key vault, You can enable Access policy-based authorization and assign correct keyvault role to the user.

My Function1.cs code:-

using System;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using Azure.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Azure;
using System.Threading.Tasks;

public static class KeyVaultFunction
{
    [FunctionName("GetKeyVaultValue")]
    public static async Task<IActionResult> GetKeyVaultValue(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
    {
        try
        {
            string keyVaultName = Environment.GetEnvironmentVariable("keyVaultName");
            var kvUri = "https://valeeykeyvlt.vault.azure.net/";

            var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
            var secretName = "secret1";
            var secret = await client.GetSecretAsync(secretName);

            string keyVaultValue = secret.Value.Value;
            return new OkObjectResult(keyVaultValue);
        }
        catch (RequestFailedException ex)
        {
            return new StatusCodeResult((int)ex.Status);
        }
        catch (Exception ex)
        {
            return new StatusCodeResult(500);
        }
    }
}

Output:-

Visual Studio settings:-

az login
az account set --subscription "xxxxxxxx"

🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 5564275 › getting-defaultazurecredential-failed-and-im-unabl
Getting DefaultAzureCredential failed and I'm unable to find my credentials - Microsoft Q&A
September 23, 2025 - Only use DefaultAzureCredential for advanced scenarios like managed identity or service principals, and ensure environment variables or Azure CLI are properly configured if you do. If you must use it, follow the official troubleshooting guide and DefaultAzureCredential documentation. Always validate your credentials by testing them in the Azure Portal’s “Try It” section or with a simple API call.
🌐
Stack Overflow
stackoverflow.com › questions › 78921912 › azure-keyvault-issue-defaultazurecredential-failed-to-retrieve-a-token-from-th
Azure keyvault issue - DefaultAzureCredential failed to retrieve a token from the included credentials - Stack Overflow
No accounts were found in the cache. VisualStudioCodeCredential.get_token failed: Failed to get Azure user details from Visual Studio Code. AzureCliCredential.get_token failed: Azure CLI not found on path DefaultAzureCredential failed to retrieve a token from the included credentials.
🌐
Port135
port135.com › home › azure › defaultazurecredential failed to retrieve a token (azure key vault)
DefaultAzureCredential failed to retrieve a token (Azure Key Vault)
December 14, 2021 - When you try to retrieve a connection string from Azure Key Vault, you may come across “DefaultAzureCredential failed to retrieve a token from the included credentials” error.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 2115287 › defaultazurecredential()-return-failed-to-retrieve
DefaultAzureCredential() return failed to retrieve a token from the included credentials. - Microsoft Q&A
For cases like that, you'll have to set the tenant specifically; for example, credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions { TenantId = "YOUR-TENANT-ID" });. When using managed connection strings, you can apply this ...