如何在mongodb数据库上实现PersistedGrantStore [英] How can I implement PersistedGrantStore on my mongodb database

查看:329
本文介绍了如何在mongodb数据库上实现PersistedGrantStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在mongodb上实现PersistedGrantStore,我已经成功地使用mongodb来存储用户和客户端,现在我正在尝试存储授权,而不是在内存中使用授权存储
我创建了一个继承自IPersistedGrantStore

I am trying to implement PersistedGrantStore on mongodb, I have managed successfully to use mongodb to store users and client and now I am trying to store grants instead of using in memory grant stores I created a class which inherits from 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

And in 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操作并获取访问令牌,因此我假设仍在使用内存存储。

It seems whatever I do none of the functions in PersistedGrantStore is called, I am not sure what I a missing here, still I can ping the server and get access token so I am assuming inmemory storage is still being used.

推荐答案

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

It seems that I didn't hit a case where the application needed to store the grant types, which are using code/hybrid flow, reference tokens, or prompting for consent. When I added AllowOfflineAccess = true to the client I can see the collection is created on the DB https://github.com/IdentityServer/IdentityServer4/issues/699

这篇关于如何在mongodb数据库上实现PersistedGrantStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆