使用自定义SecretParser / Validator进行Identity Server 4客户端证书身份验证

时间:2020-06-03 17:08:09

标签: asp.net-core identityserver4

我正在尝试让Identity Server 4使用智能卡根据用户提供的客户端证书发行令牌。我已经创建了一个新客户端以及SecretParserSecretValidator。为什么Identity Server希望我在客户定义中对机密进行硬编码。没有任何秘密在那里对硬代码有意义。我问的原因是我的SecretValidator从未运行过,除非我在客户端中输入了一些伪造的秘密。如果未提供,我会简单地返回一条消息,说Invalid Client

使用Identity Server 4验证客户端证书的正确方法是什么?我在“相互TLS”部分中找到的文档似乎并不能说明全部情况,它提供了示例客户端,其中包含硬编码的机密。

[编辑]:这个问题只是无法理解在Identity Server 4中执行Mutual TLS的含义。我将其保留在这里,但是这个问题是毫无意义的,仅说明了我对Identity身份的了解不足服务器正常工作。

1 个答案:

答案 0 :(得分:0)

在IdentityServer上声明客户端时,可以禁用对密码的需要。 只需将 RequireClientSecret 设置为false。

这里是一个例子:

new Client
{
    ClientId = "js",
    ClientName = "JavaScript Client",
    AllowedGrantTypes = GrantTypes.Code,
    RequirePkce = true,
    RequireClientSecret = false, // This disables the need for a secret 

    RedirectUris =           { "https://localhost:5003/callback.html" },
    PostLogoutRedirectUris = { "https://localhost:5003/index.html" },
    AllowedCorsOrigins =     { "https://localhost:5003" },

    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        "api1"
    }
}