【问题标题】:Identity Server 4 Client Certificate authentication with custom SecretParser/Validator使用自定义 SecretParser/Validator 的 Identity Server 4 客户端证书身份验证
【发布时间】:2020-06-07 01:38:54
【问题描述】:

我正在尝试让 Identity Server 4 使用智能卡根据用户提供的客户端证书颁发令牌。我创建了一个新客户端以及SecretParserSecretValidator。为什么 Identity Server 期望我在我的客户端定义中硬编码机密。那里没有任何对硬编码有意义的秘密。我问的原因是因为我的SecretValidator 永远不会运行,除非我在客户端中放了一些假秘密。如果没有提供,我只会收到一条回复说Invalid Client

使用 Identity Server 4 验证客户端证书的正确方法是什么?我在 Mutual TLS 部分找到的文档似乎并没有描绘出全貌,它提供了对机密进行硬编码的示例客户端。

[编辑]:这个问题只是未能理解在 Identity Server 4 中执行 Mutual TLS 意味着什么。我将把它留在这里,但这个问题有点毫无意义,只是说明我对如何识别身份缺乏了解服务器工作正常。

【问题讨论】:

  • 在 Mutual TLS 的示例中,它使用硬编码的 Secret,但如果您执行 EF/SQLite 快速入门指南,它使用 ClientSecrets 表。您可以将秘密存储在那里,如果您想要一种更动态的方法,您只需要创建一个 API 来管理该资源
  • 我的问题是为什么客户端强迫你硬编码秘密。除非您对秘密进行硬编码,否则它不起作用。如果您不硬编码秘密,您将获得无效客户端。我目前正在将我的秘密放入数据库中,所以没问题。
  • 如果您不需要 ClientSecret,则需要在 IdentityServere 上声明客户端时禁用它,请检查我的答案,看看它是否适用于您的情况。试着澄清你上面的问题,然后有一个直接的答案

标签: asp.net-core identityserver4


【解决方案1】:

在 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"
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-09
    • 2013-10-07
    • 2017-06-26
    • 1970-01-01
    • 2022-06-23
    • 1970-01-01
    • 2012-01-10
    • 2018-02-12
    相关资源
    最近更新 更多