azure-sdk-for-python
azure-sdk-for-python copied to clipboard
CLI authentication
- Package Name: azure-cli
- Package Version: 2.39.0
- Operating System: M1 Monterey
- Python Version: 3.10.3
Describe the bug
I can't authenticate to azure or get the azure credentials. I've logged in through vs code and az login through the cli. I can see my resources under the Azure pulldown in vscode but when I run code, I get
VisualStudioCodeCredential: Failed to get Azure user details from Visual Studio Code.
AzureCliCredential: Azure CLI not found on path
AzurePowerShellCredential: PowerShell is not installed
I'm just running this code:
from azure.identity import VisualStudioCodeCredential
from azure.mgmt.resource.resources import ResourceManagementClient
credential = VisualStudioCodeCredential()
client = ResourceManagementClient(
credential=credential,
subscription_id="YOUR_SUBSCRIPTION_ID"
)
To Reproduce Steps to reproduce the behavior: 1.
Expected behavior This isn't supposed to happen.
Screenshots
Azure vscode screenshot verifying that I'm logged in:
Additional context Add any other context about the problem here.
Thanks for reaching out.
It's a known issue that VisualStudioCodeCredential doesn't work with Azure Account extension versions newer than 0.9.11. A long-term fix to this problem is in progress. In the meantime, consider authenticating via the Azure CLI.
For more details, you can refer https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/TROUBLESHOOTING.md#troubleshoot-visualstudiocodecredential-authentication-issues.
Hi @kevjumba. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.
@xiangyan99 Hello, I've actually tried logging in with the azure cli. I get output when i run az login with a json dump of the correct credentials. However when I run curl 'http://169.254.169.254/metadata/identity/oauth2/token?resource=https://management.core.windows.net&api-version=2018-02-01' -H "Metadata: true" I get operation timed out and I still get the error above when I try to connect using the azure sdk. Also none of the environment variables are set for some reason..
Do you know of any additional configuration I have to do here?
From your code shared above,
credential = VisualStudioCodeCredential()
It looks to me you only tried the VSCode credential.
Have you tried
credential = AzureCliCredential()
?
I fixed the issue. You have to do this https://stackoverflow.com/questions/43983718/set-global-path-environment-variable-in-vs-code to update the vscode path.
I was running jupyter notebooks inside of the vscode cli and that was not using the same $PATH variable as the vscode terminal.
Hi @kevjumba, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.