IdentityServer4 中的签名凭证是什么?

What is the Signing Credential in IdentityServer4?

我们正在使用我们的 .NET Core Web 应用程序实施 Identity Server 4。

我浏览了 Identity Server 文档。配置身份服务器(使用 DI)时,有一行:

.AddTemporarySigningCredential

我试图了解此签名凭证是什么,但无法弄清楚。因此我不知道是否可以使用内置的临时文件,或者我是否应该提供一个不同的临时文件。

我的问题是,什么是签名凭据,我应该如何使用它?

在身份服务器文档中,这是定义:

Adds a signing key service that provides the specified key material to the various token creation/validation services. You can pass in either an X509Certificate2, a SigningCredential or a reference to a certificate from the certificate store.

所以这看起来很重要:)

授权服务器将使用密钥对令牌进行签名。资源服务器应使用密钥验证令牌的完整性。它们一起形成一个(通常是非对称的,例如 public/private)密钥(对)。默认情况下,IdentityServer 将发布 public 密钥以通过 /.well-known/openid-configuration 端点验证令牌。

对于开发场景,您通常希望跳过正确管理机密(如所述密钥)的麻烦(这对于在生产中正确执行 确实 很重要!)。对于这些开发场景,您可以选择使用临时解决方案,例如 AddTemporarySigningCredential,它曾用于 .NET Core 1.x

使用 .NET Core 2.x 这将 change 并且您将需要 AddDeveloperSigningCredential() 扩展方法。

这回答了它是什么 的问题。关于如何使用它:您只需在应用程序 Startup class.

ConfigureServices(...) 方法中根据您的 .NET Core 版本调用所需的方法

除此之外,您不需要做任何特别的事情,当然要注意在生产中使用正确的密钥对。

另请参阅 Cryptography, Keys and HTTPS and the bit on Configuring Services for Keys 上的文档。从后一份文件中,这里有一个生产案例的相关替代方案:

  • AddSigningCredential

    Adds a signing key service that provides the specified key material to the various token creation/validation services. You can pass in either an X509Certificate2, a SigningCredential or a reference to a certificate from the certificate store.