【发布时间】:2020-01-15 00:38:58
【问题描述】:
我有两个不同的客户端应用程序连接到同一个 API 客户端。我希望一个具有只读访问权限(仅获取调用),另一个也能够写入(获取、放置、发布和删除调用)。我应该如何做到这一点?
最终解决方案:
这就是我最终所做的。请务必注意,此解决方案需要额外的库。
https://www.nuget.org/packages/IdentityServer4.AccessTokenValidation/ 或者 https://github.com/IdentityServer/IdentityServer4.AccessTokenValidation
services.AddMvcCore(options =>
{
// require at least one of the scopes listed var policy =
ScopePolicy.Create("client_api_readonly", "client_api_fullaccess");
options.Filters.Add(new AuthorizeFilter(policy));
});
services.AddAuthorization(option =>
{
// where the attribute is set, require the following scope
option.AddPolicy("ApiFullAccess", p =>
p.RequireScope("client_api_fullaccess"));
});
【问题讨论】:
-
身份验证是通过客户端凭据进行的。没有用户。
标签: identityserver4