首页 > 解决方案 > 在 appsettings 中定义身份服务器客户端的未记录方式

问题描述

在探索身份服务器配置时,我发现了一个有趣的功能。这是根据官方文档在 appsettings.json 中定义客户端的方式:

{
  "IdentityServer": {
    "Clients": [
      {
        "ClientId": "TestClient1",
        "RedirectUri": "/redirect",
        "AccessTokenLifetime": 1800
      },
      {
        "ClientId": "TestClient2",
        "RedirectUri": "/redirect",
        "AccessTokenLifetime": 1800
      }
    ]
  }
}

如您所见,预计将一个数组传递到 IdentityServer 配置的“客户端”属性中。

令人惊讶的是,以下代码也有效:

{
    "IdentityServer": {
        "Clients": {
            "TestClient1": {
                "Profile": "SPA",
                "RedirectUri": "/redirect",
                "AccessTokenLifetime": 1800
            },
            "TestClient2": {
                "Profile": "SPA",
                "RedirectUri": "/redirect",
                "AccessTokenLifetime": 1800
            }
        }
    }
}

它将一个对象传递给“客户端”属性。在这种情况下,子属性的名称(“TestClient1”、“TestClient2”)映射到 ClientId。RedirectUri 也可以正常工作,但会跳过其他属性(如 AccessTokenLifetime)。

那么,为什么它会起作用?我在哪里可以找到描述这种 IdentityServer 配置方式的文档?

标签: c#asp.net-core.net-coreidentityserver4asp.net-core-identity

解决方案


这在 IdentityServer 代码上并没有什么特别之处,这就是它没有记录的原因。是读取配置的代码行。如您所见,它使用Config.Bind扩展。


推荐阅读