IdentityServer4从appsettings.json读取客户端声明

时间:2019-10-06 21:39:58

标签: asp.net-core identityserver4

如何从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解码工具中看不到它们。

1 个答案:

答案 0 :(得分:0)

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

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

在这里

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