I have a Visual Studio 2022 solution that includes multiple project types, one of which is a .NET Core website and the other is an Azure Function app.
I'm using Azure Key Vault to store secrets, and I'm using the DefaultAzureCredential to retrieve secrets in the website project without any issues.
var keyVaultUrl = Environment.GetEnvironmentVariable("AzureKeyVaultUrl");
var client = new SecretClient(new Uri(keyVaultUrl), new DefaultAzureCredential());
var storageAccountName = client.GetSecretAsync("StorageAccountName").GetAwaiter().GetResult().Value;
However, when I run the Azure Function app locally and try to retrieve secrets from Azure Key Vault in the same way, I get the following error message:
Azure.Identity.AuthenticationFailedException: SharedTokenCacheCredential authentication failed: AADSTS9002332: Application 'cfa8b339-82a2-471a-ju0L-0fc0be7a4093' (Azure Key Vault) is configured for use by Azure Active Directory users only. Please do not use the /consumers endpoint to serve this request.
I suspect that the error is related to the identity of the process running the Azure Function app in Visual Studio.
I've checked that I'm running Visual Studio as an admin, but the error still persists.
I have also checked Tools > Options > Azure Service Authentication is set correctly and signed in.
How can I check the identity of the process running the Azure Function app in Visual Studio?
Any suggestions on how to fix this issue would be greatly appreciated.