【发布时间】:2017-05-24 19:40:13
【问题描述】:
我正在尝试设置 IdentityServer4 以使用我自己的 (mongodb) 数据库,而不是文档中显示的内存示例。
为此,我配置了以下服务:
builder.Services.AddTransient<IPersistedGrantStore, PersistedGrantStore>();
builder.Services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
builder.Services.AddTransient<IClientStore, ClientStore>();
builder.Services.AddTransient<IResourceStore, ResourceStore>();
在我的数据库中,我创建了 4 个集合:“ApiResources”、“IdentityResources”和“Clients”。
在 ApiResources 中,我定义了我要保护的 API:
{
"Name" : "MyAPI",
"DisplayName" : "Test API Resource"
}
在 IdentityResources 中,我定义了我的身份:
{
"Name" : "MyIdentity",
"DisplayName" : "Test Identity Resource"
}
我已经定义了以下客户端:
{
"ClientId" : "client",
"Enabled" : true,
"ClientSecrets" : [
{
"Description" : null,
"Value" : "K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=",
"Expiration" : null,
"Type" : "SharedSecret"
}
],
"ClientName" : null,
"ClientUri" : null,
"LogoUri" : null,
"RequireConsent" : true,
"AllowRememberConsent" : true,
"AllowedGrantTypes" : [
"client_credentials"
],
"AllowedScopes" : [
"MyAPI"
],
"Claims" : [
],
"AllowedCorsOrigins" : [
]
}
我的数据库表示类似于文档中的示例。
在我的IResourceStore 实现中,对于FindIdentityResourcesByScopeAsync,我在我的IdentityResources 集合中查找范围名称(正如方法名称所暗示的那样),在我的FindApiResourcesByScopeAsync 中我在我的@987654329 中查找范围名称@collection 顾名思义。
当我尝试针对服务器验证客户端时,我收到了Requested scope not allowed: MyAPI。
但如果我将FindIdentityResourcesByScopeAsync 中的代码更改为ApiResources,那么它就可以工作了。
这是一个错误吗?还是我不明白 IdentityResources 和 ApiResources 之间有什么区别?什么时候应该使用每个?如果在FindIdentityResourcesByScopeAsync 中我应该获取我的API 资源,我应该在FindApiResourcesByScopeAsync 中获取什么?
【问题讨论】:
-
我希望 Base64 密码是假的/正在测试的。
-
@Falk 不用担心 - 确实如此。这是默认的教程哈希。
标签: identityserver4