gpt4 book ai didi

azure - 使用 Azure Key Vault 中的证书对 IdentityServer4 进行签名

转载 作者:行者123 更新时间:2023-12-03 00:39:13 25 4
gpt4 key购买 nike

我已将 pfx 证书作为 secret 上传到我的 Azure 门户,现在我想使用它来签署 IdentityServer4 中的凭据。

我在 api 启动时使用以下方法引用了保管库:

builder.AddAzureKeyVault(
$"https://{config["Vault"]}.vault.azure.net/",
config["ClientId"],
config["ClientSecret"]);

但不太确定如何将证书传递给:

 services.AddIdentityServer()
.AddSigningCredential(...)

是否可以直接从 key 保管库引用证书,或者我是否需要将证书部署到运行 API 的 Web 应用程序?

谢谢

最佳答案

您已经在构建 IConfiguration对象,因此您可以引用 pfx 键,就像引用配置中的任何其他对象一样。如果 key 在 keyvault 中,您可以像这样引用它:

// Name of your pfx in the keyvault.
var key = _configuration["pfx"];
var pfxBytes = Convert.FromBase64String(key);

// Create the certificate.
var cert = new X509Certificate2(pfxBytes);
services.AddIdentityServer()
.AddSigningCredential(cert);

我建议使用 keyvault,但您可以决定将 pfx 上传到 Web 应用程序的证书存储区。您可以在 Azure 中执行此操作,方法是转到您的 Web 应用程序 -> SSL 证书 -> 上传证书并输入密码。转到应用程序设置并添加应用程序设置 WEBSITE_LOAD_CERTIFICATES : <thumbprint> 。您要做的最后一件事是从商店检索证书并再次添加它,例如 AddSigningCredential(cert); .

关于azure - 使用 Azure Key Vault 中的证书对 IdentityServer4 进行签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44973600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com