首页 > 解决方案 > IdentityServer4 从 appsettings.json 读取客户端声明

问题描述

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

我有这个 appsettings.json:

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

而且,我像文档说的那样加载客户端配置:

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

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

标签: asp.net-coreidentityserver4

解决方案


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

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

和这里

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


推荐阅读