IdentityServer4持久化到mysql数据库

builder.Services.AddIdentityServer()
//配置存储客户端、资源等到数据库中。
.AddConfigurationStore(options =>
{
    options.ConfigureDbContext = dbBuilder =>
        dbBuilder.UseMySql(strConn, new MySqlServerVersion(new Version(5, 7, 26)),t_builder =>
        t_builder.MigrationsAssembly(migrationsAssembly));
})
//配置用户授权的同意授权的数据、Token等存储到数据库中。
.AddOperationalStore(options =>
{
    options.ConfigureDbContext = dbBuilder =>
        dbBuilder.UseMySql(strConn, new MySqlServerVersion(new Version(5, 7, 26)),t_builder =>
        t_builder.MigrationsAssembly(migrationsAssembly));
})
                .AddDeveloperSigningCredential()
                //.AddInMemoryApiScopes(Config.ApiScopes)
                //.AddInMemoryIdentityResources(Config.GetIdentityResources())
                //.AddInMemoryApiResources(Config.GetApis())
                //.AddInMemoryClients(Config.GetClients())
                .AddTestUsers(Config.GetUsers());

 

new MySqlServerVersion(new Version(5, 7, 26))不能少

Add-Migration init -Context ConfigurationDbContext -OutputDir Data/Migrations/IDS4/ConfigurationDb
Add-Migration init -Context PersistedGrantDbContext -OutputDir Data/Migrations/IDS4/PersistedGrantDb
Add-Migration initIdentity -Context AppDbContext -o Data/Migrations/IDS4/AspNetIdentity update
-Database -Context ConfigurationDbContext update-Database -Context PersistedGrantDbContext
update-Database -Context AppDbContext

 

posted @ 2022-07-24 11:07  shiningrise  阅读(211)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css