如何为 IdentityServer4 创建client_secret?



我正在使用IdentityServer4创建身份验证服务器。

我正在创建一个将使用资源所有者密码凭据访问的客户端。

但我想知道client_id和client_secret应该是什么。

例如.app,client_id应该是客户端的人类可读名称,还是应该是随机数或字符串?

client_secret是一个字符串,但它的值应该是什么?一个UUID?随机字符串?base64 字符串?

我浏览了IdentityServer4和OpenId文档,但找不到任何指导。

这是他们在文档中提供的示例。

new Client
{
ClientId = "client",
// no interactive user, use the clientid/secret for authentication
AllowedGrantTypes = GrantTypes.ClientCredentials,
// secret for authentication
ClientSecrets =
{
new Secret("secret".Sha256())
},
// scopes that client has access to
AllowedScopes = { "api1" }
}

正如您在示例中所看到的,他们设置了一个人性化的client_id。

  • > client_id:是每个客户端的公共标识符。它在授权服务器处理的所有客户端中必须是唯一的。它是公开的,但最好不要被第三方猜测。 例子:
Github: 6779ef20e75817b79602
Google: 292085223830.apps.googleusercontent.com
Instagram: f2a1ed52710d4533bde25be6da03b6e3
Windows Live: 00000000400ECB04
  • client_secret:仅由客户端和授权服务器知道。它必须是随机的,才能被猜到。生成的最佳方法是使用加密安全的库。应避免使用常见的 UUID 库。

在此处阅读有关 IdentityServer4 机密的更多信息

最新更新