2017-01-15 21 views
0

Я пытаюсь реализовать PersistedGrantStore на mongodb, мне удалось успешно использовать mongodb для хранения пользователей и клиентов, и теперь я пытаюсь хранить гранты вместо использования в хранилищах памяти. I создал класс, который наследуется от IPersistedGrantStoreКак я могу реализовать PersistedGrantStore в моей базе данных mongodb?

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 называется, я не уверен, что я отсутствующий здесь, стил l Я могу ping сервер и получить токен доступа, поэтому я предполагаю, что хранилище inmemory все еще используется.

ответ

0

Похоже, что я не попал в случай, когда приложение должно было хранить типы грантов, которые используют код/​​гибридный поток, токены ссылок или запрос на согласие. Когда я добавил AllowOfflineAccess = true для клиента, я вижу, что коллекция создается на БД https://github.com/IdentityServer/IdentityServer4/issues/699