When you use a user-assigned identity, you need to specify the client_id of the MSI in ManagedIdentityCredential().

credential = ManagedIdentityCredential(client_id="xxxxxxxx")

To get the client_id, navigate to your function app -> Identity -> User assigned -> click your user-assigned identity -> copy the client_id.

Answer from Joy Wang on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › azure-identity › azure.identity.managedidentitycredential
azure.identity.ManagedIdentityCredential class | Microsoft Learn
from azure.identity import ManagedIdentityCredential credential = ManagedIdentityCredential() # Can also specify a client ID of a user-assigned managed identity credential = ManagedIdentityCredential( client_id="<client_id>", )
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › overview › azure › identity-readme
Azure Identity client library for Python | Microsoft Learn
Managed identity authentication is supported either indirectly via DefaultAzureCredential or directly via ManagedIdentityCredential for the following Azure services:
🌐
PyPI
pypi.org › project › azure-identity
azure-identity · PyPI
1 week ago - After IMDS authentication fails, ManagedIdentityCredential 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+.
🌐
Microsoft Learn
learn.microsoft.com › ja-jp › python › api › azure-identity › azure.identity.aio.managedidentitycredential
azure.identity.aio.ManagedIdentityCredential class | Microsoft Learn
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>", )
🌐
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
from azure.identity import ManagedIdentityCredential credential = ManagedIdentityCredential() # Can also specify a client ID of a user-assigned managed identity credential = ManagedIdentityCredential( client_id="<client_id>", )
Find elsewhere
🌐
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 - In the preceding code sample, EnvironmentCredential and WorkloadIdentityCredential are removed from the credential chain. As a result, the first credential to be attempted is ManagedIdentityCredential.
🌐
Medium
medium.com › @adarshnandanwar › use-oauth-to-authenticate-managed-identity-to-any-service-2bf7df54f6e8
Authenticating Azure Managed Identities to any service using OAuth | by Adarsh Nandanwar | Medium
August 6, 2024 - Here is the Python code to read blob content. For more details on the steps involved, refer to this doc. from azure.identity import DefaultAzureCredential, ManagedIdentityCredential from azure.storage.blob import BlobServiceClient # Use ManagedIdentityCredential to get the token # System Assigned Managed Identity credential = ManagedIdentityCredential() print("Using Managed Identity for Authentication\n") # Specify the storage account, container, and blob names storage_account_name = "<your_storage_account_name>" container_name = "<your_storage_container_name>" blob_name = "lorem.txt" # URL of
🌐
Microsoft Learn
learn.microsoft.com › en-us › entra › msal › python › advanced › managed-identity
Using Managed Identity - Microsoft Authentication Library for Python | Microsoft Learn
Both MSAL Python and Azure SDK allow to acquire tokens via managed identity. Internally, Azure SDK uses MSAL Python, and it provides a higher-level API via its DefaultAzureCredential and ManagedIdentityCredential abstractions.
🌐
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
from azure.identity import ManagedIdentityCredential from azure.keyvault.secrets import SecretClient resource_id = "/subscriptions/<id>/resourceGroups/<rg>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<mi-name>" credential = ManagedIdentityCredential(identity_config={"resource_id": resource_id}) client = SecretClient("https://my-vault.vault.azure.net", credential)
🌐
Thomas Stringer
trstringer.com › authenticate-python-to-azure
Authenticate to Azure from Python | Thomas Stringer
February 28, 2021 - You can see here that it goes through the same credential order. It fails on EnvironmentCredential (because those environment variables are not set), but then immediately succeeds with ManagedIdentityCredential because this Azure VM has a managed identity assigned to it.
🌐
MCP Servers
mcpservers.org › home › claude skills & agent skills library › azure-identity-py
azure-identity-py | Claude Skills & Agent Skills Library
Azure Identity SDK for Python authentication with Microsoft Entra ID. Use for DefaultAzureCredential, managed identity, service principals, and token caching.
🌐
Medium
cloudjourney.medium.com › azure-python-sdk-authentication-336d77a17eaa
Azure Python SDK Authentication. Overview | by Cloud Journey | Medium
August 9, 2023 - Environment variables are not fully configured. ManagedIdentityCredential: Unexpected content type "text/html; charset=utf-8" Traceback (most recent call last): File "PycharmProjects/MyPythonProject/main.py", line 17, in <module> Azure Key Vault Secret client library for Python | Microsoft Docs
🌐
GitHub
github.com › Azure › azure-sdk-for-python › blob › main › sdk › identity › azure-identity › README.md
azure-sdk-for-python/sdk/identity/azure-identity/README.md at main · Azure/azure-sdk-for-python · GitHub
Managed identity authentication is supported either indirectly via DefaultAzureCredential or directly via ManagedIdentityCredential for the following Azure services: