Base solution for your next web application
Open Closed

Identity server4 integration EntityFramework (EF) as the storage mechanism #9495


User avatar
0
ashvinu created

Hello,

My app (asp.net core mvc & jquery, asp.net zero v 8.1.0) needs to use Identityserver4 for SSO. I need to replace AddInMemoryClients, AddInMemoryIdentityResources, and AddInMemoryApiResources in the ConfigureServices method in Startup.cs. I am following the documentation at http://docs.identityserver.io/en/release/quickstarts/8_entity_framework.html#refentityframeworkquickstart and https://identityserver4.readthedocs.io/en/aspnetcore1/quickstarts/8_entity_framework.html#adding-migrations

My code is as follows:

public static class IdentityServerRegistrar
    {
        public static void Register(IServiceCollection services, IConfigurationRoot configuration, Action<IdentityServerOptions> setupOptions, IWebHostEnvironment env, string connectionString)
        {
            var cert = new X509Certificate2("test.pfx", "M@test", X509KeyStorageFlags.MachineKeySet);

            services.AddIdentityServer(setupOptions)
                //.AddDeveloperSigningCredential()
                .AddSigningCredential(cert)
                //.AddInMemoryIdentityResources(IdentityServerConfig.GetIdentityResources())
                //.AddInMemoryApiResources(IdentityServerConfig.GetApiResources())
                //.AddInMemoryClients(IdentityServerConfig.GetClients(configuration))
                .AddAbpPersistedGrants<TestDbContext>()
                .AddAbpIdentityServer<User>();

            services.AddOperationalDbContext().AddDbContext<MauPassDbContext>(options => options.UseSqlServer(connectionString));
            services.AddConfigurationDbContext().AddDbContext<MauPassDbContext>(options => options.UseSqlServer(connectionString));
        }

        public static void Register(IServiceCollection services, IConfigurationRoot configuration, IWebHostEnvironment env, string connectionString)
        {
            Register(services, configuration, options => { }, env, connectionString);
        }
    }
}

I'm not sure on how to proceed with creating the tables required for Identity server.

Please assist.

Regards Kirtee


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi ashvinu

    You can create a new DbContext and inherit the ConfigurationDbContext of Identity Server. Set and migrate according to the content in the document.

  • User Avatar
    0
    ashvinu created

    Hi Maliming,

    thank you. Can you please any link/documentation which you have on this.

  • User Avatar
    0
    maliming created
    Support Team

    hi ashvinu

    I will create a demo for this.

    Please follow: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/5757