My Project is using a nuget which implementing auth token validation using DefaultAzureCredential() based SecretClient creation for reading azure keyvault.
Due to DefaultAzureCredential follows following order for auth, my code gives mangedIdentity expection while running code in visualStudio.
What shall be done to enable local debugging of code smoothly, can we change this order or can we change the code for debug mode in external nuget?
EnvironmentCredential
WorkloadIdentityCredential
ManagedIdentityCredential
AzureDeveloperCliCredential
SharedTokenCacheCredential
VisualStudioCredential
VisualStudioCodeCredential
AzureCliCredential
AzurePowerShellCredential
InteractiveBrowserCredential
https://learn.microsoft.com/en-us/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet
Exception details: (comes while debugging on local) Message:
Azure.Identity.AuthenticationFailedException : ManagedIdentityCredential authentication failed: Method not found: '!0 Microsoft.Identity.Client.AbstractApplicationBuilder`1.WithInstanceDiscovery(Boolean)'.
See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/managedidentitycredential/troubleshoot
---- System.MissingMethodException : Method not found: '!0 Microsoft.Identity.Client.AbstractApplicationBuilder`1.WithInstanceDiscovery(Boolean)'.
Thanks @christothes for the steps.
To authenticate with Visual Studio credentials, we need to check the
Azure credentialsin VS.Azure.IdentityandAzure.Security.KeyVault.Secrets.I have created an
ASP.NET CoreApplication and trying to retrieve secrets fromAzure Key Vault.In
appsettings.json, add theKeyVaultURL.With the below code Iam able to retrieve the secret without any issues.
Program.cs:Output:
As suggested by cognophile, instead of changing the order try to enable only the authentication which you want to try and check once.