So here's our setup. we have
- Angular web app
- Identity server API (ASP.NET Core 6, duende identity server)
Identity server config in Program.cs:
builder.Services
.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
builder.Services
.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
// see https://docs.duendesoftware.com/identityserver/v6/fundamentals/resources/
options.EmitStaticAudienceClaim = true;
options.IssuerUri = configuration["IssuerUri"];
})
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = b =>
b.UseMySql(conString, serverVersion, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = b =>
{
b.UseMySql(conString, serverVersion, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly));
};
})
.AddAspNetIdentity<ApplicationUser>();
builder.Services.AddAuthentication(options => {
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultForbidScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
return builder.Build();
Then after that, we call
app.useAuthorization();
app.useAuthentication();
When the web app is trying to get the openid configuration from the identity server url (/.well-known/openid-configuration), we are getting this error:
System.InvalidOperationException: No DefaultAuthenticateScheme found or no CookieAuthenticationScheme configured on IdentityServerOptions.
at Microsoft.AspNetCore.Http.AuthenticationManagerExtensions.GetCookieAuthenticationSchemeAsync(HttpContext context) in //src/IdentityServer/Extensions/HttpContextAuthenticationExtensions.cs:line 54
at Duende.IdentityServer.Services.DefaultUserSession.AuthenticateAsync() in //src/IdentityServer/Services/Default/DefaultUserSession.cs:line 135
at Duende.IdentityServer.Services.DefaultUserSession.GetSessionIdAsync() in //src/IdentityServer/Services/Default/DefaultUserSession.cs:line 215
at Duende.IdentityServer.Services.DefaultUserSession.EnsureSessionIdCookieAsync() in //src/IdentityServer/Services/Default/DefaultUserSession.cs:line 226
at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IIssuerNameService issuerNameService, IBackChannelLogoutService backChannelLogoutService) in //src/IdentityServer/Hosting/IdentityServerMiddleware.cs:line 55
at Duende.IdentityServer.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes) in //src/IdentityServer/Hosting/MutualTlsEndpointMiddleware.cs:line 94
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext context) in //src/IdentityServer/Hosting/DynamicProviders/DynamicSchemes /DynamicSchemeAuthenticationMiddleware.cs:line 47
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.g__InvokeCoreAwaited|15_0(HttpContext context, Task`1 policyTask)
at Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in //src/IdentityServer/Hosting/BaseUrlMiddleware.cs:line 27
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
