Open Closed

IdentityServer - How to configure clientIds into Database #10454


1
giamdoc created
  • Product version: 10.1.0
  • Product type: MVC
  • Product framework type: .net core

Hi team.

I'm trying to configure Identity server clients into my database. I don't want to configure it in the file "appsetting.json" So in abp how should I handle it? Please show me how to do it on abp zero For example: "Clients": [ { "ClientId": "client", "AllowedGrantTypes": [ "password" ], "ClientSecrets": [ { "Value": "def2edf7-5d42-4edc-a84a-30136c340e13" } ], "AllowedScopes": [ "default-api" ] } ] I want to include this entry in the database. Or can you guide me how to do it like the link below https://identityserver4.readthedocs.io/en/latest/quickstarts/5_entityframework.html

Thank you!


5 Answer(s)
  • 0
    ismcagdas created
    Support Team

    Hi,

    I think this is what you are looking for https://identityserver4.readthedocs.io/en/latest/quickstarts/5_entityframework.html but we haven't tried it with AspNet Zero. Let us know if you face any problems.

  • 0
    giamdoc created

    Thank you for the feedback.

    If I use the method you sent, will the information stored in the database be cached? Or it will access to the Database every time there is a request. Is there any solution for me to use the database and AddMemory at the same time?

  • 0
    ismcagdas created
    Support Team

    Hi @giamdoc

    Unfortunately, I don't know the details. If IDSRV supports caching, I guess it will use it in your app as well.

  • 0
    giamdoc created

    Thank you.

    I have found the solution. However I am having problem getting Database Data from Startup class. Is there a way to access DbConext at MVC's startup?

    Ex: if (bool.Parse(_appConfiguration["IdentityServer:IsEnabled"])) {

                //Get ClientID from Database
                
                var context = services.BuildServiceProvider().GetService<MyDbContext>();
                var clientIds = GetClientIds(context);
                
                //What do I need to write to be able to access the database here?
                
                IdentityServerRegistrar.Register(services, _appConfiguration, options => options.UserInteraction =
                    new UserInteractionOptions
                    {
                        LoginUrl = "/Account/Login",
                        LogoutUrl = "/Account/LogOut",
                        ErrorUrl = "/Error"
                    }, clientIds);
            }
    
  • 0
    ismcagdas created
    Support Team

    Hi,

    I think this is not the correct approach for IDSRV. I think you need to use .AddClientStore<MyCustomClientStore>() in IdentityServerRegistrar.cs as shown below;