使用 Azure Key Vault 中的证书对 IdentityServer4 进行签名
Use certificate in Azure Key Vault to sign IdentityServer4
我已将 pfx 证书作为机密上传到我的 Azure 门户,现在我想使用它在 IdentityServer4 中签署凭据。
我在 api 的启动过程中使用以下方法获得了对 vault 的引用:
builder.AddAzureKeyVault(
$"https://{config["Vault"]}.vault.azure.net/",
config["ClientId"],
config["ClientSecret"]);
但不太确定如何将证书传给:
services.AddIdentityServer()
.AddSigningCredential(...)
是否可以直接从密钥库引用证书,或者我是否需要将证书部署到 api 运行 所在的 Web 应用程序?
谢谢
您已经在构建 IConfiguration
对象,因此您可以像引用配置中的任何其他对象一样引用 pfx 密钥。
如果密钥在 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);
我建议为此使用密钥保管库,但您可以决定将 pfx 上传到 Web 应用程序的证书存储区。您可以在 Azure 中执行此操作,方法是转到您的 Web 应用 -> SSL 证书 -> 上传证书并输入密码。转到“应用程序设置”并添加应用程序设置 WEBSITE_LOAD_CERTIFICATES : <thumbprint>
。您要做的最后一件事是从商店检索证书并再次添加它,例如 AddSigningCredential(cert);
.
我已将 pfx 证书作为机密上传到我的 Azure 门户,现在我想使用它在 IdentityServer4 中签署凭据。
我在 api 的启动过程中使用以下方法获得了对 vault 的引用:
builder.AddAzureKeyVault(
$"https://{config["Vault"]}.vault.azure.net/",
config["ClientId"],
config["ClientSecret"]);
但不太确定如何将证书传给:
services.AddIdentityServer()
.AddSigningCredential(...)
是否可以直接从密钥库引用证书,或者我是否需要将证书部署到 api 运行 所在的 Web 应用程序?
谢谢
您已经在构建 IConfiguration
对象,因此您可以像引用配置中的任何其他对象一样引用 pfx 密钥。
如果密钥在 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);
我建议为此使用密钥保管库,但您可以决定将 pfx 上传到 Web 应用程序的证书存储区。您可以在 Azure 中执行此操作,方法是转到您的 Web 应用 -> SSL 证书 -> 上传证书并输入密码。转到“应用程序设置”并添加应用程序设置 WEBSITE_LOAD_CERTIFICATES : <thumbprint>
。您要做的最后一件事是从商店检索证书并再次添加它,例如 AddSigningCredential(cert);
.