15

I'm trying to integrate a NoSql data store into Identity Server 4 such as Cosmos DB. I was wondering if someone out there has done something similar and/or if it's possible.

Dustin
  • 735
  • 1
  • 7
  • 16
  • 2
    Yes. Just implement your own `IClientStore` and `IPersistedGrantStore` etc. If ypu look at `IdentityServer4.EntityFramework` it should give you a good idea of how to achieve what you likely want. – Mardoxx Aug 23 '17 at 19:10
  • Thanks. I will look into that. It seems like I 'd also have to implement the Configuration and Operational Store.. but they seem to have rooted dependencies on SQL.. i.e: .AddConfigurationStore(builder => builder.UseSqlServer... and .AddOperationalStore(builder => builder.UseSqlServer. Any thoughts? thanks again! – Dustin Aug 23 '17 at 19:16
  • That is for configuration of EntityFramework. (I believe it is for setting the IQueryableProvider or something like that, not quote clued up on EF internals). You probably needn't worry about that! – Mardoxx Aug 23 '17 at 20:39
  • 2
    Just remembered cosmosdb is like rebranded documentdb. If you set your cosmosdb to be able to use mongodb api... I wrote this a while back. https://github.com/EdwardBlair/IdentityServer4.MongoDBDriver you could use this. Should also give a better idea of how to intrgrate a different persistance layer. HTH – Mardoxx Aug 23 '17 at 20:41
  • I scrapped the idea though, as 1) cosmosdb is hella expensive. 2) mssql is more than fast enough! 3) I trust IdSrv devs more than I trust my own code – Mardoxx Aug 23 '17 at 20:43
  • TBH there isn't a huge amount to persist - look at those interfaces and see what tables Entity Framework takes care of, and you'll see that writing your own persistence into some nosql isn't a massive undertaking. – Mashton Aug 23 '17 at 20:51
  • Gotcha. I will look into this.. Thanks a lot for chipping in! :) – Dustin Aug 23 '17 at 22:09

2 Answers2

7

Off-course, It is possible to use NoSQL database for IdentityServer4. Why not?

Here is an example with MongoDB

"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());
  ...
  }

There is another github project cloudscribe, ASP.NET Core multi-tenant web application foundation with management for sites, users, roles, claims and more. This project is implementing PostgreSQL (ORDBMS) and MySql for IdentityServer. In this project, you can get the idea about how to implement a system that allows switching among databases.

MJK
  • 3,434
  • 3
  • 32
  • 55
  • Thanks @MJK! I'm going to use the MongoDB implementation as a example to build my own. :) – Dustin Aug 28 '17 at 15:07
  • @Dustin I am glad that you found your way, please do not forget to mark as answer, if it helps – MJK Aug 28 '17 at 15:35
0

The above answer is working but a bit old. As of Sept 2021, I have implemented the same by registering custom stores directly in IdentityServer() pipeline.

By default, these custom implementations will get registered with Transient lifetime. In my case, MongoDB has been used, so that implemented custom stores to read Identity data from NoSQL collections.

services.AddIdentityServer()
                .AddAspNetIdentity<ApplicationUser>()            
                .AddClientStore<CustomClientStore>()
                .AddCorsPolicyService<InMemoryCorsPolicyService>()
                .AddResourceStore<CustomResourceStore>()
                .AddPersistedGrantStore<CustomPersistedGrantStore>()
                .AddDeveloperSigningCredential();
Gopinath
  • 246
  • 1
  • 4
  • 16