Skip to content

Latest commit

 

History

History
37 lines (31 loc) · 1.85 KB

MongoImplementation.md

File metadata and controls

37 lines (31 loc) · 1.85 KB

Mongo Implementation overview

Both QuickstartIdentityServer projects samples follow similar approach to use MongoDB for configuration data.

  1. IdentityServer4 configuration to use mongo as repository is based on DI and IdentityServerBuilderExtensions - Similar to
    8_EntityFrameworkStorage sample implementation - Hence we perform all "initial plumbing" in ConfigureServices() method at startup.cs.
          public void ConfigureServices(IServiceCollection services)
  { 
  ...
    // ---  configure identity server with MONGO Repository for stores, keys, clients and scopes ---
    services.AddIdentityServer()
           .AddTemporarySigningCredential()
           .AddMongoRepository()
           .AddClients()
           .AddIdentityApiResources()
           .AddPersistedGrants()
           .AddTestUsers(Config.GetUsers());
  ...
  }
  1. In the IdentityServerBuilderExtensions.cs extension hold methods to enable DI related work executed by ConfigureServices() as listed above. It's important to highlight that AddMongoRepository() method configure a simple Repository Design Pattern to handle persistence to MongoDB. IdentityServerBuilderExtensions.cs configure DI to use custom implementation for required interfaces such as IClientStore, IResourceStore and IPersistedGrantStore enabling IdentityServer4 to interact with MongoDB seamlessly.

  2. After that we just need to make sure all required IdentityServer4 Interfaces, listed above, are implemented leveraging MongoRepository. e.g. :

public class CustomResourceStore : IResourceStore { ... private IEnumerable GetAllApiResources() { return _dbRepository.All(); } ... }