我按照Identity Server 4教程设置了一个项目
http://docs.identityserver.io/en/latest/quickstarts/6_aspnet_identity.html
.
根据所列的教程,它们的组合包括API、JavaScript客户端、MVC客户端和Identity server。
它使用的是EF持久化存储,而不是内存中的存储,并使用ASP核心标识,如finally touch。
有了SQL Server,它工作得很好,但是我想迁移到PostgresSQL,作为自我教育的一部分(坦率地说,我更喜欢它而不是SQL Server)。
直到我登录时,它抛出了这个错误:
InvalidOperationException:缺少子索赔
我已经看完了所有的代码,但不明白为什么会这样。
我所做的唯一更改是Identity Server 4启动文件中的以下内容:
// CHANGE HERE: UseNpgsql instead of UseSqlServer
services.AddDbContext<ApplicationDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("PostgresqlConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
string connectionString = Configuration.GetConnectionString("PostgresqlConnection").ToString();
var builder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
})
.AddConfigurationStore(options =>
{
// CHANGE HERE: UseNpgsql instead of UseSqlServer
options.ConfigureDbContext = b => b.UseNpgsql(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
// UseNpgsql instead of UseSqlServer
options.ConfigureDbContext = b => b.UseNpgsql(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
});
无论我去哪里看,这似乎是我唯一需要做的改变。
使用了Net Core 3.1。
有什么建议遗漏了什么?
编辑1:
问题似乎在于ASP核心身份和PostgreSQL。还是不知道怎么解决。