我需要使用clientId,clientSecret,TenantId和vaultURL从Azure密钥保管库读取机密/值。我对所有这些都有价值。我需要使用这些值读取存储在蔚蓝金库中的值。
对代码有帮助吗?
答案 0 :(得分:0)
想也分享这些(我看到一个人回答了),只是为了让您也拥有它们
https://docs.microsoft.com/en-us/azure/key-vault/general/developers-guide
和
https://www.microsoft.com/en-us/download/details.aspx?id=45343来获取样本
答案 1 :(得分:0)
如果您想要一个示例,可以参考本教程:Azure Key Vault client library for .NET。下面是我的测试代码。
string clientSecret = "client secret";
string clientId = "client id";
var secreturi = "https://****.vault.azure.net";
KeyVaultClient kvClient = new KeyVaultClient(async (authority, resource, scope) =>
{
var adCredential = new ClientCredential(clientId, clientSecret);
var authenticationContext = new AuthenticationContext(authority, null);
return (await authenticationContext.AcquireTokenAsync(resource, adCredential)).AccessToken;
});
var keyvaultSecret = await kvClient.GetSecretAsync($"{secreturi}", "testsecret").ConfigureAwait(false);
Console.Write(keyvaultSecret.Value);