【问题标题】:Is it possible to use a NoSQL for Identity Server 4?是否可以将 NoSQL 用于 Identity Server 4?
【发布时间】:2017-08-23 18:55:11
【问题描述】:

我正在尝试将 NoSql 数据存储集成到 Identity Server 4 中,例如 Cosmos DB。我想知道是否有人做过类似的事情和/或是否有可能。

【问题讨论】:

  • 是的。只需实现您自己的IClientStoreIPersistedGrantStore 等。如果您查看IdentityServer4.EntityFramework,它应该可以让您很好地了解如何实现您可能想要的。
  • 谢谢。我会调查的。似乎我还必须实现配置和操作存储。但它们似乎对 SQL 有根依赖。即: .AddConfigurationStore(builder => builder.UseSqlServer... 和 .AddOperationalStore(builder => builder .UseSqlServer。有什么想法吗?再次感谢!
  • 用于EntityFramework的配置。 (我相信它是用于设置 IQueryableProvider 或类似的东西,而不是引用 EF 内部的线索)。您可能不必担心!
  • 刚刚记住的 cosmosdb 就像重新命名的 documentdb。如果你将你的 cosmosdb 设置为能够使用 mongodb api……我前段时间写了这个。 github.com/EdwardBlair/IdentityServer4.MongoDBDriver 你可以用这个。还应该更好地了解如何集成不同的持久层。 HTH
  • 我放弃了这个想法,因为 1) cosmosdb 太贵了。 2) mssql 足够快! 3) 我更信任 IdSrv 开发人员而不是我自己的代码

标签: asp.net-core identityserver4 azure-cosmosdb


【解决方案1】:

当然,IdentityServer4 可以使用 NoSQL 数据库。为什么不呢?

这是MongoDB 的示例

startup.cs 中 ConfigureServices() 方法中的“初始管道”。

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

还有另一个 github 项目 cloudscribe,ASP.NET Core 多租户 Web 应用程序基础,可管理站点、用户、角色、声明等。这个项目正在为 IdentityServer 实现 PostgreSQL (ORDBMS) 和 MySql。在这个项目中,您可以了解如何实现一个允许在数据库之间切换的系统。

【讨论】:

  • 谢谢@MJK!我将使用 MongoDB 实现作为示例来构建我自己的。 :)
  • @Dustin 很高兴你找到了自己的方式,如果有帮助,请不要忘记标记为答案
【解决方案2】:

上述答案有效,但有点旧。截至 2021 年 9 月,我通过直接在 IdentityServer() 管道中注册自定义存储实现了相同的功能。

默认情况下,这些自定义实现将注册到 Transient 生命周期。在我的例子中,使用了 MongoDB,因此实现了自定义存储以从 NoSQL 集合中读取身份数据。

services.AddIdentityServer()
                .AddAspNetIdentity<ApplicationUser>()            
                .AddClientStore<CustomClientStore>()
                .AddCorsPolicyService<InMemoryCorsPolicyService>()
                .AddResourceStore<CustomResourceStore>()
                .AddPersistedGrantStore<CustomPersistedGrantStore>()
                .AddDeveloperSigningCredential();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    • 2018-06-27
    • 2017-12-07
    • 2018-05-15
    相关资源
    最近更新 更多