After migrating my website from .NET Core 2.2 to 3.1.1, my api endpoints suddenly started trying to redirect my api request to a default login page (/Account/Login?ReturnUrl=, which I don't even have in any of my routes).
My api is using a JWT bearer authentication scheme, with JWT Challenge Scheme, but still the redirect happened.
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
I finally found a solution to the problem, but I have no idea why it actually helped.
Initially I had my services set as:
services
.AddIdentity<IdentityUser, IdentityRole>()
.AddSignInManager()
.AddEntityFrameworkStores<CleWebToolsIdentityDbContext>();
But that did the redirect.
What finally solved my problem was setting them to:
services
.AddIdentityCore<IdentityUser>()
.AddRoles<IdentityRole>()
.AddSignInManager()
.AddEntityFrameworkStores<CleWebToolsIdentityDbContext>();
Can somebody tell me what is going on here?
How does the AddIdentity-method cause the redirect, even though the challenge scheme should be JWT?