【发布时间】:2021-07-15 14:03:21
【问题描述】:
我正在一个剃须刀页面应用程序中实现 Identity Server。
当请求speech ApiResource 时,identityserver 返回“invalid_scope”。我的理解是资源是一组范围。所以,我期待身份服务器返回语音资源中定义的范围。
注意:我将 speech 添加为 ApiScope,它可以正常工作,但不会添加 speech.synthesize 和 payment.subscription 范围。
这是我定义 ApiScopes 的方式:
public static IEnumerable<ApiScope> ApiScopes =>
new List<ApiScope>
{
new ApiScope("speech.synthesize", "Speech synthesis",new []{"api.create" }),
new ApiScope("payment.subscription", "Subscription service"),
new ApiScope("payment.manage", "Manage Payment"),
};
这是我定义 ApiResource 的方式:
public static IEnumerable<ApiResource> ApiResources =>
new List<ApiResource>
{
new ApiResource("speech", "Speech API")
{
Scopes = { "speech.synthesize", "payment.subscription" }
}
};
这是客户端配置:
public static IEnumerable<Client> Clients =>
new List<Client>
{
new Client
{
ClientId = "client",
// no interactive user, use the clientid/secret for authentication
AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
// secret for authentication
ClientSecrets =
{
new Secret("secret".Sha256())
},
AlwaysSendClientClaims = true,
// scopes that client has access to
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"speech"
}
}
};
这里有什么问题?谁能帮我理解这个问题。
如果不对范围进行分组,Api 资源的作用是什么。
【问题讨论】:
标签: asp.net-core identityserver4 openid