【问题标题】:How can I implement PersistedGrantStore on my mongodb database如何在我的 mongodb 数据库上实现 PersistedGrantStore
【发布时间】: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


    【解决方案1】:

    似乎我没有遇到应用程序需要存储授权类型的情况,这些授权类型使用代码/混合流、引用令牌或提示同意。 当我向客户端添加 AllowOfflineAccess = true 时,我可以看到该集合是在数据库上创建的 https://github.com/IdentityServer/IdentityServer4/issues/699

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-13
      • 2019-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      相关资源
      最近更新 更多