在appsettings中定义Identity Server客户端的未公开方法

问题描述 投票:1回答:1

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

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

如您所见,应该将一个数组传递给IdentityServer配置的“ Clients”属性。

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

{
    "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-core asp.net-identity identityserver4
1个回答
0
投票

您的第二个代码不正确,因为您在对象上执行列表行为。

您可以使用以下代码来读取appsetting.json:

configuration.GetSection("IdentityServer:Clients")

Injection IConfiguration interface

© www.soinside.com 2019 - 2024. All rights reserved.