【问题标题】:How set swagger client claims with identityServer4如何使用 identityServer4 设置招摇的客户声明
【发布时间】:2020-05-26 19:30:37
【问题描述】:

我正在使用 IDS4 颁发的访问令牌保护 .NET Core Web API。

它有效,我在客户端配置中添加了一些声明,如下所示:

// ... other code
new Client
{
    ClientId = "apiclient",
    AllowedGrantTypes = GrantTypes.ClientCredentials,
    ClientSecrets = {
        new Secret("mysupersecret".Sha256())
    },
    AllowedScopes = { 
        "joinot", 
        JwtClaimTypes.Role,
    },
    Claims = new List<Claim>() { new Claim("role", "WonderWoman"), new Claim("VatId", "123abc") },
},
// ... other code

这些是我在 webapi 中看到的声明。

我找到了我添加的前缀“client_”。

出于测试目的,我使用的是 swagger,我有这个配置:

new Client {
    ClientId = "swagger_api_client",
    ClientName = "Swagger API Client",
    AllowedGrantTypes = GrantTypes.Implicit,
    AllowAccessTokensViaBrowser = true,
    RedirectUris = {"http://localhost:57303/swagger/oauth2-redirect.html"},
    AllowedScopes = { 
        "joinot", 
        JwtClaimTypes.Role, 
    },
    Claims = new List<Claim>() { new Claim("role", "ManOfSteel"), new Claim("VatId", "abc123") },
    RequireConsent = false
},

这意味着我必须通过交互式用户进行身份验证,然后才能调用 webapi。

当我这样做时,我在 webapi 中找到的声明并不像我预期的那样。

“client_role”和“client_VatId”不在列表中。

如何插入控制台和 swagger 客户端的声明?

【问题讨论】:

    标签: oauth-2.0 swagger asp.net-core-webapi identityserver4


    【解决方案1】:

    您可以将AlwaysSendClientClaims 设置为 true :

    Claims = new List<Claim>() { new Claim("role", "WonderWoman"), new Claim("VatId", "123abc") },
    AlwaysSendClientClaims =true,
    

    如果设置,将为每个流发送客户端声明。如果不是,则仅用于客户端凭据流(默认为 false)。因此,即使不设置该属性,使用客户端凭据流的控制台应用程序也可以正常工作。

    参考文档:http://docs.identityserver.io/en/latest/reference/client.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-27
      • 2017-05-24
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 2023-01-03
      • 2018-05-18
      相关资源
      最近更新 更多