question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DefaultAzureCredential: How to know which credential was used internally?

See original GitHub issue

Library name and version

Azure.Identity 1.6.0-beta.1

Query/Question

I love the flexibility of DefaultAzureCredential. I use it in many applications, for instance to support different credentials for my local debugging, during workflows or in production without the need for code changes or a factory pattern.

So i know that the DefaultAzureCredential sequentially calls GetToken() on all the included credentials. The order is clearly specified in the documentation.

My use case was that is got different behavior for my xUnit test running from the command line or from VS Test Explorer. It turned out the command line used the AzureCliCredential and the Test Explorer used the VisualStudioCredential.

It took me a while to figure this out and if i could log this in my code that would have helped a lot.

So I was wondering how i can verify which credential was actually used for the token by DefaultAzureCredential. This could be informative and for instance used in debug logging.

Regards, Martijn

Environment

.NET SDK (reflecting any global.json): Version: 6.0.201 Commit: ef40e6aa06

Runtime Environment: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.201\

Host (useful for support): Version: 6.0.3 Commit: c24d9a9c91

.NET SDKs installed: 3.1.417 [C:\Program Files\dotnet\sdk] 5.0.406 [C:\Program Files\dotnet\sdk] 6.0.100 [C:\Program Files\dotnet\sdk] 6.0.101 [C:\Program Files\dotnet\sdk] 6.0.103 [C:\Program Files\dotnet\sdk] 6.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
christothescommented, Apr 1, 2022

Hi @martijnvanschie - IsAccountIdentifierLoggingEnabled is not yet released, but it should be available after next week’s release.

1reaction
christothescommented, Mar 31, 2022

Hi @martijnvanschie - This information can be displayed by enabling logging. Please see the following for how to enable it. https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md#logging

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication and the Azure SDK
The DefaultAzureCredential attempts to figure out what environment you are running in, and uses the most appropriate credential for the ...
Read more >
Azure SDK: What's new in the Azure Identity August 2020 ...
DefaultAzureCredential uses a credential chain internally to attempt authentication with multiple credentials. Each credential in the Azure ...
Read more >
Azure Identity 201 - DefaultAzureCredential Options
By default, DefaultAzureCredential will use system-assigned identity, but if your Azure host uses a user-assigned identity you'll want to tell ...
Read more >
Azure Identity 301 - ChainedTokenCredential - Jon Gallant
This is where ChainedTokenCredential come into the picture. You know the exact list of credentials you want your application to attempt.
Read more >
Azure.Identity.CredentialUnavailableException: ...
In Visual Studio, go to Tools > Options. Expand "Azure Service Authentication" > "Account Selection." If you see a "Reenter your credentials" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found