如何为IdentityServer4创建一个client_secret?

问题描述 投票:0回答:1

我正在使用IdentityServer4创建一个认证服务器。

我正在创建一个客户端,这个客户端将使用资源所有者密码凭证进行访问。

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

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。

authentication identityserver4 openid
1个回答
1
投票
  • client_id: 是一个 公共 每个客户的标识符。它必须是 独一无二 在授权服务器处理的所有客户端上。它是公开的,但最好不要让第三方猜到。例如
Github: 6779ef20e75817b79602
Google: 292085223830.apps.googleusercontent.com
Instagram: f2a1ed52710d4533bde25be6da03b6e3
Windows Live: 00000000400ECB04
  • client_secret: 只是被客户端和授权服务器知道。它必须是随机的,不能让人猜到。最好的生成方式是使用 加密 安全库。您应该避免使用常见的UUID库。

阅读更多关于 IdentityServer4 的秘密 此处

© www.soinside.com 2019 - 2024. All rights reserved.