我正在编写IdentityServer4实现并使用快速入门项目here。为什么我在IdentityServer4的同意屏幕上看到重复的范围?
当您定义一个ApiResource(现在使用InMemory类)时,它看起来像IdentityServer创建一个与资源同名的Scope。例如
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource("api", "My API")
};
}
将创建一个名为“API”的范围(这是在ApiResource构造函数中完成的)。如果我在客户端对象上使用“api”作为允许的范围(使用InMemoryClients作为概念证明),并在我的JavaScript客户端的身份验证请求中的作用域查询字符串参数中请求此作用域,我会收到invalid_scope错误消息。
我发现以下this documentation您可以通过作用域属性,像这样
new ApiResource
{
Name = "api",
DisplayName = "Custom API",
Scopes = new List<Scope>
{
new Scope("api.read"),
new Scope("api.write")
}
}
添加作用域到ApiResource所以现在,如果我不是定义我ApiResource这样并请求作用域api.read和api.write (并将它们添加到客户端对象上的AllowedScopes属性),那么一切正常,除了显示重复范围的同意页面。它显示了2次api.read和api.write 2次。看到这里
同意画面客户端配置如下:
new Client
{
ClientId = "client.implicit",
ClientName = "JavaScript Client",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RedirectUris = { "http://localhost:3000/health-check" },
PostLogoutRedirectUris = { "http://localhost:3000" },
AllowedCorsOrigins = { "http://localhost:3000" },
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"customApi.read", "customApi.write"
}
}
这究竟是为什么?我做了什么明显错误?
更新: 这里发现的文件,显示范围是只列出一次的一部分...
你有多少API资源?他们的范围将被复制。请考虑从'/ .well-known/openid-configuration'端点发布'scopes_supported'内容。 –
@IlyaChumakov我发布了它。我绝对只有一个API资源,所以我迷失在为什么会发生这种情况 –