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