【发布时间】: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