如何在数据库中的IdentityServer4中添加新客户端?

tho*_*vdb 5 identityserver4

在最初的测试中,我始终AddInMemoryClients按照其文档中所述使用IdentityServer4 的配置。

但是,我正在将其部署到我们的测试环境中,并且想要摆脱配置文件,因此我设置了Entity Framework集成

现在,所有客户端ID,客户端机密,作用域……都以加密方式保留在数据库中。但是,添加新客户端更加困难。

什么是适当的配置方式?

使用实体框架迁移?

我知道IdentityServer4上有一个UI,但这是唯一的“简便”方法吗?

小智 0

var context = scope.ServiceProvider.GetRequiredService<ConfigurationDbContext>()
context.Database.Migrate()
use this too create context 

Code for client json for seed

new Client
{
    ClientId = "js",
    AllowedGrantTypes = GrantTypes.CodeAndClientCredentials,
    RequirePkce = false,
    RequireConsent = false,
    RedirectUris = JsConfig.RedirectUris.Split(',').Select(s => s.Trim()).ToArray(),
    //FrontChannelLogoutUri = "https://localhost:44300/signout-oidc",
    PostLogoutRedirectUris = JsConfig.PostLogoutRedirectUris.Split(',').Select(s => s.Trim()).ToArray(),
    AllowedCorsOrigins = JsConfig.AllowedCorsOrigins.Split(',').Select(s => s.Trim()).ToArray(),
    AllowPlainTextPkce = true,
    AllowOfflineAccess = true,
    AllowAccessTokensViaBrowser = true,
    AlwaysIncludeUserClaimsInIdToken = true,
    AlwaysSendClientClaims = true,
    ClientSecrets = new [] { new Secret("secret".Sha512()) },
    //AllowedScopes = { "openid", "profile", "scope2" },
    AllowedScopes = new List<string>
     {
        //Omitted for brevity        
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        IdentityServerConstants.StandardScopes.Email
     },
    ClientName = "eXate Portal",
    DeviceCodeLifetime = 0,

}

For Add
context.Clients.Add(client.ToEntity())

Run Code Online (Sandbox Code Playgroud)