I'm using Microsoft.Azure.keyVault
trying to get a secret from a key vault in Azure.
I've registered an application as both Native and Web API.
Logging on to the AD is successful (can confirm this by getting a valid AccessToken
on AuthenticationContext.AcquireTokenAsync
).
In Azure AD both applications have been given Access Control (IAM) and Access Policies in the Key Vault. I have confirmed that the Key Vault Base Url and the Secret Name are correct but when making the following call
var sec = kv.GetSecretAsync("https://xxxxxxx.vault.azure.net", "xxsecretnamexx").GetAwaiter().GetResult();
I keep getting the error
{"Operation returned an invalid status code 'Unauthorized'"} Microsoft.Azure.KeyVault.Models.KeyVaultErrorException
One sidenote: Attempting to do this by logging in as a user. The code to get the token is as follows
.AcquireTokenAsync(resourceUri,clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.SelectAccount))
We have working code using the id and secret of an registered Azure AD application that has rights to the key vault.
Trying to do the same thing without using the id and secret of an associated registered Azure AD application but instead have a login prompt displayed when getting the access token to Azure AD.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…