【问题标题】:IdentityServer4 Asp.Net Core Identity with custom storeIdentityServer4 Asp.Net Core Identity 与自定义存储
【发布时间】:2017-04-20 09:48:26
【问题描述】:

我将 IdentityServer4 与 Asp.Net Identity 一起使用。我需要实现一个听起来很简单的自定义身份存储,但是我看到的所有示例都使用我没有使用的 EntityFramework 核心。

也许还有另一种使用自定义用户存储的方法。谁能指出我使用 IdentityServer4 使用自定义凭据存储的示例。

【问题讨论】:

  • 您是否连接到现有数据库?为 asp.net 身份实施自定义商店会给您带来什么?为什么不使用您现有的代码直接连接?
  • 我正在连接到现有数据库。我真的不知道这里最好的方法是什么。我正在尝试使用 ASP.NET Core Identity 扩展我为 IdentityFramework4 找到的示例。这似乎是一个很好的起点。我以为这很简单,但结果并非如此。
  • 看看这个系列:linkedin.com/pulse/… 不确定它是否正是您正在寻找的,但它确实使用自定义商店进行了解释:
  • 如果它是一个现有数据库 - 只需实现帐户控制器以使用 ADO.NET 连接到它 - 关于身份服务器,这里没什么特别的。
  • 谢谢贝鲁兹。我缺少的部分内容是如何将我的用户存储与 IdentityServer 连接起来,因此我没有使用 IdentityFramework 示例中描述的“InMemoryUsers”。我确定如何在某处的文档中做到这一点。我还不确定这一切,但这是一大步。

标签: identityserver4 asp.net-core-identity


【解决方案1】:

基本上归结为实现 IProfileService 和 IResourceOwnerPasswordValidator 并使用配置生成器注册实现。

这篇博文展示了一个简洁的实现

https://damienbod.com/2017/04/14/asp-net-core-identityserver4-resource-owner-password-flow-with-custom-userrepository/

这个扩展类是一切发生的地方

public static class CustomIdentityServerBuilderExtensions
{
    public static IIdentityServerBuilder AddCustomUserStore(this IIdentityServerBuilder builder)
    {
        builder.Services.AddSingleton<IUserRepository, UserRepository>();
        builder.AddProfileService<CustomProfileService>();
        builder.AddResourceOwnerValidator<CustomResourceOwnerPasswordValidator>();

        return builder;
    }
}

【讨论】:

  • 感谢分享博文!
猜你喜欢
  • 2019-07-19
  • 1970-01-01
  • 2021-04-11
  • 2019-02-16
  • 2019-05-01
  • 2019-01-12
  • 2015-05-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多