2017-01-15 80 views
0

我想在MongoDB上實現PersistedGrantStore,我已經成功地使用mongodb來存儲用戶和客戶端,現在我試圖存儲撥款而不是在內存授權商店中使用 I創建從IPersistedGrantStore我如何在我的MongoDB數據庫上實現PersistedGrantStore

繼承
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功能被稱爲類,我不知道我缺少這裏, STIL l我可以ping服務器並獲取訪問令牌,所以我假設內存存儲仍在使用中。

回答

0

看來我沒有遇到應用程序需要存儲授權類型的情況,這些授權類型使用代碼/混合流程,引用令牌或提示徵求同意。 當我將AllowOfflineAccess = true添加到客戶端時,我可以看到在DB上創建了集合 https://github.com/IdentityServer/IdentityServer4/issues/699

相關問題