Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Failed to get user details from Visual Studio Code #17364

Closed
kummerer94 opened this issue Mar 16, 2021 · 6 comments
Closed

[BUG] Failed to get user details from Visual Studio Code #17364

kummerer94 opened this issue Mar 16, 2021 · 6 comments
Assignees
Labels
Azure.Identity customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@kummerer94
Copy link

Describe the bug

I am trying to use DefaultAzureCredential from the azure-identity python package, but it will not work together with VS code.

I have logged into Azure in VS Code using the "Azure Account" extension. The device code login does work for my setup, but not the VisualStudioCodeCredential.

A similiar report can be found here: Azure/azure-sdk-for-net#14770. However, I am on Windows.

Expected behavior

The credential should be retrieved from VS code.

Actual behavior (include Exception or Stack Trace)

I get the exception: CredentialUnavailableError: Failed to get Azure user details from Visual Studio Code.

To Reproduce
Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)

  1. Use VisualStudioCodeCredential().
  2. Query the Graph API using the msgraphcore package.

Environment:

  • Name and version of the Library package used: azure-identity==1.5.0, msgraphcore==0.0.2
  • Hosting platform or OS and .NET runtime version (dotnet --info output for .NET Core projects): Windows 10 Pro, Python 3.8.3
  • IDE and version : Visual Studio Code 1.54.3
@jsquire jsquire transferred this issue from Azure/azure-sdk-for-net Mar 16, 2021
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 16, 2021
@jsquire
Copy link
Member

jsquire commented Mar 16, 2021

Hi @kummerer94. Thank you for reaching out and we regret that you're experiencing difficulties. I'm going to move this over to the Python SDK repository to ensure that the folks best able to assist can be looped in.

@chlowell chlowell added Azure.Identity and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Mar 16, 2021
@chlowell chlowell self-assigned this Mar 16, 2021
@chlowell
Copy link
Member

Thanks for opening this issue. VisualStudioCodeCredential attempts to read VS Code's settings and authentication data. One possible point of failure is that when it can't read the settings, it assumes you're signed in to Azure Public Cloud, and will fail to authenticate if you are not. So, first question--are you logged in to a different cloud?

If not, could you please try it again with debug-level logging? For example:

import logging
import sys

logger = logging.getLogger('azure.identity')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)

That will capture the details of any exception.

@chlowell chlowell added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Mar 16, 2021
@kummerer94
Copy link
Author

@chlowell Thanks for the quick response!

I ran the authentication again with your suggestion and that was the output:

>>> VisualStudioCodeCredential().get_token("user.read")   
Exception retrieving VS Code credentials: "Expecting value: line 113 column 5 (char 3741)"
Traceback (most recent call last):
  File "\.venv\lib\site-packages\azure\identity\_internal\win_vscode_adapter.py", line 82, in get_credentials
    environment_name = _get_user_settings()
  File "venv\lib\site-packages\azure\identity\_internal\win_vscode_adapter.py", line 69, in _get_user_settings
    data = json.load(file)
  File "C:\Program Files\Python38\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Program Files\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\Python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Python38\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 113 column 5 (char 3741)
VisualStudioCodeCredential.get_token failed: Failed to get Azure user details from Visual Studio Code.
Traceback (most recent call last):
  File "venv\lib\site-packages\azure\identity\_internal\decorators.py", line 27, in wrapper
    token = fn(*args, **kwargs)
  File "venv\lib\site-packages\azure\identity\_credentials\vscode.py", line 69, in get_token
    token = self._redeem_refresh_token(scopes, **kwargs)
  File "venv\lib\site-packages\azure\identity\_credentials\vscode.py", line 82, in _redeem_refresh_token
    raise CredentialUnavailableError(message="Failed to get Azure user details from Visual Studio Code.")
azure.identity._exceptions.CredentialUnavailableError: Failed to get Azure user details from Visual Studio Code.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "venv\lib\site-packages\azure\identity\_internal\decorators.py", line 27, in wrapper
    token = fn(*args, **kwargs)
  File "venv\lib\site-packages\azure\identity\_credentials\vscode.py", line 69, in get_token
    token = self._redeem_refresh_token(scopes, **kwargs)
  File "venv\lib\site-packages\azure\identity\_credentials\vscode.py", line 82, in _redeem_refresh_token
    raise CredentialUnavailableError(message="Failed to get Azure user details from Visual Studio Code.")
azure.identity._exceptions.CredentialUnavailableError: Failed to get Azure user details from Visual Studio Code.

@ghost ghost added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-author-feedback Workflow: More information is needed from author to address the issue. labels Mar 17, 2021
@chlowell
Copy link
Member

Looks like json.load can't handle your VS Code settings. The file is %APPDATA%/Code/User/settings.json, is there anything unusual about its content around line 113?

@chlowell chlowell added needs-author-feedback Workflow: More information is needed from author to address the issue. and removed needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Mar 17, 2021
@kummerer94
Copy link
Author

The problem seems to be that I commented out a few lines in my settings. While normally JSON does not support comments, the settings.json is usually fine with this. I guess you are using the standard json module to parse this, though.

I have removed the comments and it works now! Thanks for helping me out.

@ghost ghost added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-author-feedback Workflow: More information is needed from author to address the issue. labels Mar 18, 2021
@chlowell
Copy link
Member

You're welcome. Please open another issue if you encounter another problem.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Identity customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

3 participants