DefaultAzureCredential: How to know which credential was used internally?
See original GitHub issueLibrary 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:
- Created a year ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
Hi @martijnvanschie -
IsAccountIdentifierLoggingEnabled
is not yet released, but it should be available after next week’s release.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