【发布时间】:2023-01-03 17:25:19
【问题描述】:
我在身份服务器 4 中有一个项目,我在中间件应用程序中有一个创建方法,所以我想根据客户端调用 API 设置一些默认值(可能是客户端名称)
场景,我们有一个用于注册用户的 API 端点,将由多个客户端使用单独的客户端 ID 和客户端名称(如“MobileAPP”、“网站”和“CRMAPP”)调用
我想根据调用“注册用户”API 的客户端添加一些默认值。
可以提出建议或线索以实现这一目标。
我试图读取请求上下文,但没有找到任何内容。我找到了一种方法来记录基于客户端定义的here 但不是我们的 API 方法中的客户端信息。
客户定义:
new Client
{
ClientName = "Test Mobile App",
ClientId = "test_mobile_app",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets =
{
new Secret("mykey".Sha256())
},
AllowedScopes =
{
"app.openid",
"app.profile",
"user.manage"
},
AllowOfflineAccess = true,
RefreshTokenUsage = TokenUsage.ReUse,
AccessTokenLifetime = 3600,
RefreshTokenExpiration = TokenExpiration.Absolute,
AbsoluteRefreshTokenLifetime = 2592000
}
政策:
option.AddPolicy("MobileAppScope", policy =>
{
policy.RequireAuthenticatedUser();
policy.RequireClaim("scope", "user.manage")
.RequireClaim("scope", "app.openid")
.RequireClaim("scope", "app.profile");
});
授权属性:
[Authorize(Policy = "MobileAppScope", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
【问题讨论】:
标签: c# api .net-core identityserver4