【发布时间】:2017-05-30 05:47:48
【问题描述】:
我正在尝试在 mongodb 上实现 PersistedGrantStore,我已经成功地使用 mongodb 来存储用户和客户端,现在我正在尝试存储授权而不是在内存授权存储中使用 我创建了一个继承自 IPersistedGrantStore 的类
public class PersistedGrantStore : IPersistedGrantStore
{
public async Task<IEnumerable<PersistedGrant>> GetAllAsync(string subjectId)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
return await persistedGrantService.GetAllPersistedGrant(subjectId);
}
public async Task<PersistedGrant> GetAsync(string key)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
return await persistedGrantService.GetPersistedGrantByKey(key);
}
public async Task RemoveAllAsync(string subjectId, string clientId)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
await persistedGrantService.RemoveAllBySubjectIdAndClientId(subjectId, clientId);
}
public async Task RemoveAllAsync(string subjectId, string clientId, string type)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
await persistedGrantService.RemoveAllBySubjectIdAndClientIdAndType(subjectId, clientId, type);
}
public async Task RemoveAsync(string key)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
await persistedGrantService.RemoveAllByKey(key);
}
public async Task StoreAsync(PersistedGrant grant)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
await persistedGrantService.InsertPersistedGrant(grant);
}
}
在 startup.cs 中
public void ConfigureServices(IServiceCollection services)
{
var builder = services.AddIdentityServer()
.AddSigningCredential(cert)
.AddInMemoryIdentityResources(IdentityConfiguration.GetIdentityResources())
.AddInMemoryApiResources(ApiResourceConfiguration.GetApiResources());
builder.Services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
builder.Services.AddTransient<IProfileService, ProfileService>();
builder.Services.AddTransient<IClientStore, ClientStore>();
builder.Services.AddTransient<IPersistedGrantStore, PersistedGrantStore>();
}
似乎无论我做什么都没有调用 PersistedGrantStore 中的任何功能,我不确定我在这里缺少什么,但我仍然可以 ping 服务器并获取访问令牌,所以我假设仍在使用内存存储。
【问题讨论】:
标签: c# identityserver4 asp.net-core-1.1