Hello Gongya Yu ,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
Problem
I understand that you signed in to Azure using the Azure Sign In extension within VS Code and you're asking if this sign-in also handles authentication for their Python code accessing Azure services.
Solution
To answer your question, the authentication does not automatically carry over to your Python code running within VS Code. To ensure your Python code can authenticate and access Azure services there four or more methods. I will list four here with the links for detail steps:
- Azure CLI Authentication. If you've already signed in to Azure using the Azure CLI, you can use the
AzureCliCredential
from theazure-identity
library. Link: https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python#azure-cli-credential - Environment Variables. You can set environment variables for service principal or managed identity, and use the
DefaultAzureCredential
class. Link: https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python#environment-variables and https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python#defaultazurecredential - Managed Identity. If your code is running on an Azure service that supports managed identities, use the
DefaultAzureCredential
class. Link: https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python#managed-identity-authentication - Service Principal. You can use a service principal's credentials directly in your Python code. Link: https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python#clientsecretcredential
Therefore, signing in to Azure through the Azure Sign In extension in Visual Studio Code helps manage Azure resources within the VS Code environment. So, for Python code to interact with Azure services, you need to explicitly handle authentication using the appropriate Azure SDK libraries and methods.
References
For more reading/information and additional resources kindly use the provided links by the right side of this page.
Accept Answer
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam