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] DefaultAzureCredential VisualStudioCredential unable to retrieve an access token. #29540

Closed
AndrewCS149 opened this issue Jun 28, 2022 · 9 comments
Assignees
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. needs-author-feedback More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue.

Comments

@AndrewCS149
Copy link
Contributor

AndrewCS149 commented Jun 28, 2022

Library name and version

Azure.Identity.DefaultAzureCredential

Describe the bug

I am attempting to authenticate to Azure using the DefaultAzureCredential in my program. However, after I create the DefaultAzureCredential attempt to use it, I receive an error stating that the VisualStudioCredential.GetToken was unable to retrieve an access token.

var options = new DefaultAzureCredentialOptions()
{
    ExcludeAzureCliCredential = true,
    ExcludeAzurePowerShellCredential = true,
    ExcludeEnvironmentCredential = true,
    ExcludeInteractiveBrowserCredential = true,
    ExcludeManagedIdentityCredential = true,
    ExcludeSharedTokenCacheCredential = true,
    ExcludeVisualStudioCodeCredential = true,
    ExcludeVisualStudioCredential = false
};

var cred = new DefaultAzureCredential(options);

When I attempt to actually use the token, I receive this exception:

Azure-Identity: VisualStudioCredential.GetToken was unable to retrieve an access token. Scopes: [ user_impersonation ] 
ParentRequestId: <id> Exception: Azure.Identity.CredentialUnavailableException (0x80131500): 
Process "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\fc0rxpqz.bks\TokenService\Microsoft.Asal.TokenService.exe" 
has failed with unexpected error: TS003: Error, TS007: resource parameter must be a URI or a GUID.

Expected behavior

Successfully authenticate and interact with Azure resources.

Actual behavior

Receive an exception stating 'VisualStudioCredential.GetToken was unable to retrieve an access token'.

Reproduction Steps

  1. Open VS 2022
  2. Create new console project
  3. Create new DefaultAzureCredential
  4. Attempt to interact with Azure resources

Environment

Windows 11
.NET 6
Visual Studio 2022

@ghost ghost added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Jun 28, 2022
@azure-sdk azure-sdk added Azure.Identity Client This issue points to a problem in the data-plane of the library. needs-team-triage This issue needs the team to triage. labels Jun 28, 2022
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Jun 28, 2022
@jsquire jsquire added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-team-triage This issue needs the team to triage. labels Jun 29, 2022
@jsquire
Copy link
Member

jsquire commented Jun 29, 2022

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@LeePhillipsFreemarket
Copy link

I am also having the issue exactly as described.

@AndrewCS149
Copy link
Contributor Author

@jsquire Is there any update on this?

Thank you!

@AndrewCS149
Copy link
Contributor Author

@LeePhillipsFreemarket Have you found any workaround/solution for this?

@LeePhillipsFreemarket
Copy link

@AndrewCS149 Not exactly. When developing locally i'm just using a direct connection string now. When the service is used in azure using managed identity.

Another way round would be to log into azure using powershell as a fallback and just setting ExcludeVisualStudioCredential to true so it doesn't use it.

I've not found a workaround that actually makes use of the VisualStudioCredential.

@christothes
Copy link
Member

Hi @AndrewCS149 - Could you provide some sample code that shows how you are calling the azure resource? Are you using another client SDK or fetching the token manually?

Also, could you provide the log output of your repro? Details can be found here:
https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md#logging

@christothes christothes added the needs-author-feedback More information is needed from author to address the issue. label Oct 26, 2022
@ghost ghost removed the needs-team-attention This issue needs attention from Azure service team or SDK team label Oct 26, 2022
@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label Nov 2, 2022
@ghost
Copy link

ghost commented Nov 2, 2022

Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@TKoval
Copy link

TKoval commented Nov 3, 2022

Same here, I'm creating instances of blob client like this:

new BlobServiceClient(new Uri(blobServiceUri), new DefaultAzureCredential(options))

When I perform any operation on this client afterwards the error I get is the following:

Status: 401 (Server failed to authenticate the request. Please refer to the information in the www-authenticate header.)
ErrorCode: InvalidAuthenticationInfo

Additional Information:
AuthenticationErrorDetail: Issuer validation failed. Issuer did not match.

Content:
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidAuthenticationInfo</Code><Message>Server failed to authenticate the request. Please refer to the information in the www-authenticate header.
RequestId:94ebddbc-301e-0011-80c8-ef1a10000000
</Message><AuthenticationErrorDetail>Issuer validation failed. Issuer did not match.</AuthenticationErrorDetail></Error>

I'm using .net 6, function app v4 running on Windows 11. Core tools version is 4.0.4829. function runtime version is 4.11.2.19273.

What I'm trying to do is to use managed identity for blob storage access and fallback to VisualStudioCredential while debugging my function app locally. The best workaround I found so far is to set VisualStudioTenantId explicitly:

var options = new DefaultAzureCredentialOptions
{
    ExcludeAzureCliCredential = true,
    ExcludeAzurePowerShellCredential = true,
    ExcludeEnvironmentCredential = true,
    ExcludeInteractiveBrowserCredential = true,
    ExcludeManagedIdentityCredential = false,
    ExcludeSharedTokenCacheCredential = true,
    ExcludeVisualStudioCodeCredential = true,
    ExcludeVisualStudioCredential = false,
    VisualStudioTenantId = "<your Azure AD Tenant ID here>"
};

return new BlobServiceClient(new Uri(blobServiceUri), new DefaultAzureCredential(options));

I found this solution here: #13228. The theory is that this bug occurs when accounts have multiple tenants but my account has only one tenant.
Doing it this way has one disadvantage, it takes few seconds for ManagedIdentityCredential to fail and use a fallback. There is a feature request to speed it up: #29471.
EDIT: Solution with setting AZURE_TENANT_ID env variable from #13228 works too.
EDIT 2: My account actually has access to 2 tenants, so maybe it's expected behavior. It would be nice to have some more user-friendly errors in this case.

@ghost ghost removed the no-recent-activity There has been no recent activity on this issue. label Nov 3, 2022
@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label Nov 11, 2022
@ghost
Copy link

ghost commented Nov 11, 2022

Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@ghost ghost closed this as completed Nov 26, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 25, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. needs-author-feedback More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue.
Projects
None yet
Development

No branches or pull requests

7 participants