IdentityServer4 Mysql相关问题
最近需要用到IdentityServer认证功能,但是数据库采用的是Mysql,Identityserver4官方的实例采用的是SQLServer。
最近研究了如何使用Mysql持久化IdentityServer4相关数据,以及Identity数据。具体操作步骤如下:
1、修改初始化数据库代码:
setup.cs文件:
private void InitializeDatabase(IApplicationBuilder app)
{
using (var serviceScope = app.ApplicationServices.GetService().CreateScope())
{
serviceScope.ServiceProvider.GetRequiredService().Database.Migrate();
serviceScope.ServiceProvider.GetRequiredService().Database.Migrate();
var context = serviceScope.ServiceProvider.GetRequiredService();
context.Database.Migrate();
if (!context.Clients.Any())
{
foreach (var client in Config.GetClients())
{
context.Clients.Add(client.ToEntity());
}
context.SaveChanges();
}</