【发布时间】:2017-05-23 22:01:44
【问题描述】:
我正在尝试确定 ApiResource 和 Client 是如何联系在一起的。
我如何确保从客户端请求令牌的人正在为特定的 ApiResource 请求令牌,该 ApiResource 可以访问该 ApiResource?
试过被 Scopes 捆绑在一起吗?
这里是 QuickStart 中的一些稍作修改的代码:
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource("api1Resource", "My API")
{
Scopes =
{
new Scope("api1"),
new Scope("api1.ro"),
new Scope("offline_access")
},
UserClaims = { "role", "user" }
}
};
}
// client want to access resources (aka scopes)
public static IEnumerable<Client> GetClients()
{
// client credentials client, for APIs
return new List<Client>
{
new Client
{
ClientId = "apiClient",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets =
{
// Secret that can be created and given to ITSM_API
new Secret("secret".Sha512(), "ITSM_API Secret")
},
AllowedScopes = { "api1", "api1.ro", "offline_access" }
},
// resource owner password grant client, for interactive users
new Client
{
ClientId = "userClient",
AllowedGrantTypes = GrantTypes.List
(
GrantType.ResourceOwnerPassword,
"offline_access"
),
ClientSecrets =
{
new Secret("secret".Sha512(), "userClient Secret")
},
UpdateAccessTokenClaimsOnRefresh = true,
AllowedScopes = { "api1", "api1.ro", "offline_access" },
AbsoluteRefreshTokenLifetime = 86400,
AllowOfflineAccess = true,
RefreshTokenUsage = TokenUsage.ReUse
}
};
}
【问题讨论】:
-
"offline_access"不是有效的授权类型。
标签: c# asp.net-core identityserver4