【问题标题】:IdentityServer4 read client claims from appsettings.jsonIdentityServer4 从 appsettings.json 读取客户端声明
【发布时间】:2020-06-08 09:02:59
【问题描述】:

如何从 appsettings.json 文件中读取客户端声明?

我有这个 appsettings.json:

"IdentityServer": {
     "Clients": [
       {
         "Enabled": true,
         "ClientId": "client1",
         "AlwaysSendClientClaims": true,
         "Claims": [
           {
             "Type": "custom_claim1",
             "Value": "value1"
           },
           {
             "Type": "custom_claim2",
             "Value": "value2"
           }
         ]
       }
     ]
}

而且,我加载了客户端配置like the docs says

var builder = services.AddIdentityServer(opts =>
{
    /// Opts removed for simplicity
})
   .AddInMemoryClients(Configuration.GetSection("IdentityServer:Clients"));

一切正常,除了客户声称。我在 Jwt.io 解码工具中看不到它们。

【问题讨论】:

  • 在添加内存客户端时,我见过的示例中没有一个包含Claims
  • 您认为问题出在阅读客户声明的原因是什么?似乎实际的问题是声明没有出现在令牌中:我在 Jwt.io 解码工具中看不到它们。这是一个完全不同的问题。您能否确认没有加载索赔,也就是说,客户没有索赔?
  • 当我使用代码(相同的设置)在内存中配置客户端时,声明被添加到 jwt.问题是当我尝试从 json 加载时。
  • 有一个关于reading clients from json 的未解决问题,但由于您的应用程序没有崩溃,这可能与您的问题无关。
  • 仍然,您确认没有为客户加载声明吗?

标签: asp.net-core identityserver4


【解决方案1】:

由于无法从 json 反序列化 Claim 对象的当前实现,因此从 appSettings.json 绑定 Clients[] 中的 Claims 集合时出现问题。

https://github.com/IdentityServer/IdentityServer4/issues/2573

这里

https://github.com/IdentityServer/IdentityServer4/pull/3887/files/ed14abc204960b2d5ca3418a868882a698e54d90

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 2020-03-27
    • 2019-07-06
    • 2017-10-09
    • 2020-05-26
    • 1970-01-01
    相关资源
    最近更新 更多