I setup a project as per Identity Server 4 tutorial http://docs.identityserver.io/en/latest/quickstarts/6_aspnet_identity.html.
Combination of which has everything including API, JavaScript client, MVC Client, and Identity server as per tutorials listed.
It is using EF persisted storage rather then in memory and is using ASP Core Identity, as finally touch.
With SQL Server it works fine, however i wanted to migrate to PostgresSQL as part of self education (and frankly prefer it over sqlserver).
Everything worked up until moment when i login upon which it throws this error:
InvalidOperationException: sub claim is missing
I've gone through all of the code but cannot figure out why this is the case.
Only change i have made is this in the Identity Server 4 startup file:
// 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));
});
Everywhere i looked this seems to be the only change i need to make.
Net Core 3.1 used.
Any advice what is missing?
EDIT 1:
The issue seems to be with ASP Core Identity and PostgreSQL. Still can't figure out how to fix it.
Looks like you are missing the .AddAspNetIdentity<ApplicationUser>()
.
Your final builder
should look like
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));
})
.AddAspNetIdentity<ApplicationUser>();