Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure.Identity.CredentialUnavailableException in dotnet program

I have recently taken over a project and am trying to start the dotnet backend server on my mac. I keep getting the error you see below in the Program.cs file when i run the application.

Exception has occurred: CLR/Azure.Identity.CredentialUnavailableException
An unhandled exception of type 'Azure.Identity.CredentialUnavailableException' occurred in Microsoft.Extensions.Configuration.AzureAppConfiguration.dll: 'DefaultAzureCredential failed to retrieve a token from the included credentials. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/defaultazurecredential/troubleshoot
- EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot
- ManagedIdentityCredential authentication unavailable. Multiple attempts failed to obtain a token from the managed identity endpoint.
- Operating system Darwin 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 isn't supported.
- VisualStudioCodeCredential authentication unavailable. Token acquisition failed. Ensure that you have authenticated in VSCode Azure Account. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/vscodecredential/troubleshoot
- Please run 'az login' to set up account
- Az.Account module >= 2.2.0 is not installed.'
 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception     Azure.Identity.CredentialUnavailableException : EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, String additionalMessage)
   at Azure.Identity.EnvironmentCredential.<GetTokenImplAsync>d__12.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at Azure.Identity.EnvironmentCredential.<GetTokenAsync>d__11.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Azure.Identity.DefaultAzureCredential.<GetTokenFromSourcesAsync>d__15.MoveNext()

The application uses azure keyvault for enviroment variables.

What i tried:

  1. Asked for my azure user to be invited to the project.
  2. My azure account has been granted owner rights.
  3. Installed azure cli and used az login on vs code.
  4. Added data reader rights on the key vault access control.
  5. Added my user to access policies with the same permissions as the dev before me.

I also sure to log in on the azure account in visual studio code before i ran program. Also tried in regular visual studio for mac os, but had the same result.

like image 496
cc_9313 Avatar asked May 21 '26 07:05

cc_9313


1 Answers

I came accross this issue with the same error message. I could either call az loginprior to running the program

or I could call DefaultAzureCredential with the parameter includeInteractiveCredentials:true

var secretClient = new SecretClient(new Uri(keyVaultUri), new DefaultAzureCredential(includeInteractiveCredentials: true));

this opens a browser and tries to login the current user and enables the login.

source: https://azuresdkdocs.blob.core.windows.net/$web/dotnet/Azure.Identity/1.4.1/index.html#enabling-the-interactive-authentication-with-the-defaultazurecredential

like image 116
Jan Avatar answered May 23 '26 20:05

Jan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!