1
votes

I am using IdentityServer4 with Asp.Net Identity. I need to implement a custom identity store which sounds easy enough, but all of the examples I see use EntityFramework core which I am not using.

Perhaps there is another way to use a custom user store. Can anyone point me to an example of using a custom credential store using IdentityServer4.

1
Are you connecting to an existing database? What does implementing a custom store for asp.net identity buy you? Why not use your existing code to connect directly? - leastprivilege
I am connecting to an existing database. I don't really know what the best approach is here. I am trying to expand an an example I found for IdentityFramework4 using ASP.NET Core Identity. It seemed like a good place to start. I thought it would be simple, but it is not turning out that way. - Greg P
Take a look at this series:linkedin.com/pulse/… not sure if it exactly what you're looking for but it does explain using a custom store: - Behrooz
If it is an existing database - just implement the account controller to connect to it using ADO.NET - nothing special here with regards to identity server. - leastprivilege
Thanks Behrooz. Part of what I was missing was how to connect my user store with IdentityServer so I wasn't using "InMemoryUsers" as described in the IdentityFramework sample. I'm sure how to do that was in that documentation somewhere. I am still not sure about all of it yet, but this was a big step. - Greg P

1 Answers

5
votes

Basically it boils down to Implementing an IProfileService and an IResourceOwnerPasswordValidator and registering the implementations with the config builder.

This blog post shows a succinct implementation of this

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

This extension class is where it all happens

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

        return builder;
    }
}