asp.net-core - OpenID Connect 和 IdentityServer4:API 与范围
问题描述
http://docs.identityserver.io/en/latest/reference/api_resource.html说“API 必须至少有一个范围。”
IdentityServer4 似乎没有强制执行此限制:我有
public static IEnumerable<ApiResource> GetApis(IConfiguration config)
{
return new ApiResource[]
{
new ApiResource("orm", "Our ORM"),
};
}
(这里没有范围)并且我的软件确实可以工作并且似乎不会产生任何错误。我是否正确理解这里有错误但 IdentityServer4 只是没有诊断错误?
此外,我有
new Client
{
ClientId = "mvc",
ClientName = "MVC Client",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
ClientSecrets = { new Secret("XXX".Sha256()) },
RedirectUris = { ormClientURL + "/signin-oidc" },
FrontChannelLogoutUri = ormClientURL + "/signout-oidc",
PostLogoutRedirectUris = { ormClientURL + "/signout-callback-oidc" },
AllowOfflineAccess = true,
AllowedScopes = { "openid", "profile", "orm" }
},
尽管我没有"orm"
定义范围,但它仍然有效。
为什么它确实有效?
如何正确解决这个问题?(我应该定义哪些客户和范围?)
解决方案
似乎 ApiResource 构造函数使用提供的名称和 displayName 添加了一个 Scope:
public ApiResource(string name, string displayName)
: this(name, displayName, null)
{
}
public ApiResource(string name, string displayName, IEnumerable<string> claimTypes)
{
if (name.IsMissing()) throw new ArgumentNullException(nameof(name));
Name = name;
DisplayName = displayName;
Scopes.Add(new Scope(name, displayName));
if (!claimTypes.IsNullOrEmpty())
{
foreach (var type in claimTypes)
{
UserClaims.Add(type);
}
}
}
https://github.com/IdentityServer/IdentityServer4/blob/master/src/Storage/src/Models/ApiResource.cs
推荐阅读
- javascript - 如何为 javascript 中的inquirer.prompt 问题的答案创建函数参数(变量)?MySQL也参与其中
- c++ - 我不知道为什么这个 static_assert() 代码不起作用
- python - TypeError:列表索引必须是整数或切片,而不是str,discord py
- r - 跨列的逐行操作
- python - 检查一个列表的每个元素是否是另一个列表的所有元素的倍数
- clion - 如何在 CLion 中包装一长串值?
- c# - 与 ASP.NET MVC BeginExecuteCore 等效的 ASP.NET Core
- java - 如何使用 selenium java 在对话框中自动滚动
- html - 相对位置如何使 dom 节点在固定位置上绘制?
- java - 使用 twaitforfile 或自定义 java 代码将文件从一个目录传输到另一个目录时如何诱导时间延迟?