【发布时间】:2021-06-16 22:31:44
【问题描述】:
我正在尝试使用带有 OpenIdConnect 的 .net core 2.1 创建 azure key vault。
我尝试过的:-
我已经尝试参考以下堆栈溢出问题的答案
- Creating Azure Key Vault using .NET assembly (Microsoft.Azure.KeyVault)
- Azure Key Vault - programmatic creation
其他
Nuget 包:- Microsoft.Azure.Management.KeyVault
代码:-
private async Task AddKeyVaultAsync()
{
var clientId = "xxxx";
var tenantId = "xxxx";
var clientSecret = "xxxx";
var objectId = "xxxx";
var subscriptionId = "xxx";
// The resource group to create the vault in.
string resourceGroupName = "Vaults-Resource-Group";
// The name of the vault to create.
string vaultName = "web-app-01-vault";
var parameters = new VaultCreateOrUpdateParameters()
{
Location = "southeast asia",
Properties = new VaultProperties()
{
TenantId = Guid.Parse(tenantId),
AccessPolicies = new List<AccessPolicyEntry>()
{
new AccessPolicyEntry
{
TenantId = Guid.Parse(tenantId),
ObjectId = objectId,
Permissions = new Permissions
{
Secrets = new List<string> { "all" },
Keys = new string[] { "all" }
}
}
}
}
};
//problem in following line
var tokenCredentials = new TokenCloudCredentials(subscriptionId, token);
var keyVaultManagementClient = new KeyVaultManagementClient(tokenCredentials);
// Create the vault
await keyVaultManagementClient.Vaults.CreateOrUpdateAsync(resourceGroupName, vaultName, parameters);
}
但我被困在了
//problem in the following line
var tokenCredentials = new TokenCloudCredentials(subscriptionId, token);
如何创建令牌(TokenCloudCredentials 中的参数)和 TokenCloudCredentials? 我应该使用哪个 Nuget 包来创建 TokenCloudCredentials?
我也试过用:-
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecret)
.Build();
创建 KeyVaultManagementClient。但我不确定该怎么做?
还有其他(更好的)方法来创建 KeyVaultManagementClient 吗?
【问题讨论】:
标签: c# azure azure-keyvault