asp.net-core - ApiResource 返回“invalid_scope”身份服务器
问题描述
我在剃刀页面应用程序中实现身份服务器。
请求speech
ApiResource 时,identityserver 返回“invalid_scope”。我的理解是资源是一组范围。所以,我期待身份服务器返回语音资源中定义的范围。注意:我将其添加speech
为 ApiScope 它可以正常工作,但它不会添加speech.synthesize
andpayment.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 资源的作用是什么。
解决方案
作为客户,您需要 ApiScopes,而不是 ApiResources。另外一个 ApiResource 可以指向一个 ApiScope。
ApiResource 表示 API 实例,而不是 Scope。ApiResources 就像客户端,但对于 APIs。
有关IdentityResource、ApiResource 和 ApiScope 之间区别的更多详细信息,请参阅我的答案
推荐阅读
- javascript - 从代码后面执行 JS 函数(带参数)
- python - 如何在 Python 中使用 OpenCV 在检测部分绘制矩形?
- python - 正则表达式 findall 输出不符合预期
- python - Pandas 数据帧的递归转置
- node.js - 如何在 GraphQL 模式中使用“十进制”作为字段类型?
- azure-devops - 如何获取每个 Azure DevOps 项目的激活签入策略列表?
- javascript - 如何在javascript中转义字符串并执行一些(如果)逻辑?
- python - 如何从在 django 中声明为 CharField 的模型字段创建动态 SelectBox
- apache - 如何使用 .htaccess 使网站运行 Index.html 文件?
- javascript - 提交后如何清除数组