I'm trying to connect my .Net Core 3.1 app up to an Azure Key Vault. I've followed the quickstart tutorial, and am getting the following error:
Microsoft.Extensions.Configuration.AzureAppConfiguration.KeyVaultReferenceException: 'DefaultAzureCredential authentication failed.. ErrorCode:, Key:Authentication:Twitter:ConsumerAPIKey
The inner exception is:
MsalServiceException: AADSTS70002: The client does not exist or is not enabled for consumers
The CreateHostBuilder method looks like this:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.ConfigureAppConfiguration((hostingContext, config) =>
{
var settings = config.Build();
config.AddAzureAppConfiguration(options =>
{
options.Connect(settings["ConnectionStrings:AppConfig"])
.ConfigureKeyVault(kv =>
{
kv.SetCredential(new DefaultAzureCredential());
});
});
})
.UseStartup<Startup>();
});
I've found very little reference to this online, except one post relating to using multiple credentials (which I am not).
Can anyone give me a way forward on this: some clue as to what might be causing it?
EDIT
The following seems to work:
var defaultAzureCredentialsOptions = new DefaultAzureCredentialOptions()
{
SharedTokenCacheTenantId = <tenant id>,
SharedTokenCacheUsername = <my azure username>,
ExcludeInteractiveBrowserCredential = false,
ExcludeEnvironmentCredential = false,
InteractiveBrowserTenantId = <tenant id>
};
config.AddAzureAppConfiguration(options =>
{
options.Connect(settings["ConnectionStrings:AppConfig"])
.ConfigureKeyVault(kv =>
{
kv.SetCredential(new DefaultAzureCredential(defaultAzureCredentialsOptions));
});
});
Whilst this does work (as far as it goes), I now have the Tenant ID and my username hard-coded; along with a pop-up when I launch the site asking me to log-in.