Based on this old thread :
It's important to understand that Managed Identity feature in Azure is ONLY relevant when, in this case, the App Service is deployed. This would mean you would probably want to use
DefaultAzureCredential()
from theAzure.Identity
library which is compatible both when running locally and for the deployed web app. This class will run down the hierarchy of possible authentication methods and when running locally I prefer to use a service principal. Run the following in Azure CLI to create a service principal:az ad sp create-for-rbac --name localtest-sp-rbac --skip-assignment
. You then add the service principallocaltest-sp-rbac
in the IAM for the required Azure services. I recommend reading this article for more information and how to configure your local environment: https://learn.microsoft.com/en-us/azure/developer/python/configure-local-development-environment You can see the list of credential types thatDefaultAzureCredential()
goes through in the Azure docs.
More links to help :
https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/TROUBLESHOOTING.md