ASP.NET Core 5 with IdentityServer4: in loop after the login
I have my new project with ASP.NET Core 5 and ASP.NET Core Identity. I want to add AddOpenIdConnect with IdentityServer4. I have other projects already in place that they are working fine and up and running. Then, I copied the code and paste in my new project.
services.AddSession(options =>
{
options.Cookie.Name = ".puresourcecode.session";
options.IdleTimeout = TimeSpan.FromHours(12);
});
var idsrv = Configuration.GetSection("IdentityAuthentication").Get<IdentityServerSettings>();
if (idsrv.UseIdentityServer)
{
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "oidc";
})
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
options.Cookie.Name = "puresourcecode.cookie";
})
.AddOpenIdConnect("oidc", options =>
{
options.Authority = idsrv.IdentityServerUrl;
options.ClientId = idsrv.ClientId;
options.ClientSecret = idsrv.ClientSecret;
#if DEBUG
options.RequireHttpsMetadata = false;
#else
options.RequireHttpsMetadata = true;
#endif
options.ResponseType = "code";
options.Scope.Clear();
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.Scope.Add("roles");
options.Scope.Add("offline_access");
options.ClaimActions.MapJsonKey("role", "role", "role");
options.GetClaimsFromUserInfoEndpoint = true;
options.SaveTokens = true;
options.SignedOutRedirectUri = "/";
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = JwtClaimTypes.Name,
RoleClaimType = JwtClaimTypes.Role,
};
});
}
I added the new package Microsoft.AspNetCore.Authentication.OpenIdConnect. I configured my IdentityServer to redirect the user after the login to /signin-oidc and the grant types is authorization_code. As I said I have lot of other projects that are working fine.
When I run the new application, I redirect to the IdentityServer. I login but the the browser is in loop because it is opening again and again the IdentityServer page for authentication (I don't need to authenticate again because I have already authenticated myself).
Do you have any idea? What I have to change?
This is the configuration of my IdentityServer4
Basic
Authentication
Token
Here the video of what it is happening.