The issue is when it is logining in, the sign in page keeps refreshing and calling okta. It looks like the app is in an infinite loop. The attachment shows tjhe issue. Could anyone please solve this issue for me? it is kind of urgent.
My web app is .net core 2 web app.
This part is my configuration in Configuration services:
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(options=> { options.Cookie.SameSite = SameSiteMode.Lax; })
.AddOpenIdConnect(options =>
{
// Configuration pulled from appsettings.json by default:
options.ClientId = Configuration["okta:ClientId"];
options.ClientSecret = Configuration["okta:ClientSecret"];
options.Authority = Configuration["okta:Authority"];
options.CallbackPath = "/Account/Login";
//options.ResponseType = "code";
options.SaveTokens = true;
options.UseTokenLifetime = false;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("openid");
options.Scope.Add("profile");
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name"
};
});
Login action:
public IActionResult Login()
{
if (!HttpContext.User.Identity.IsAuthenticated)
{
return Challenge(OpenIdConnectDefaults.AuthenticationScheme);
}
return RedirectToAction("Index", "Home");
}
Configure method in startup:
app.UseSession();
loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseAuthentication();
app.Use(async (context, next) =>
{
if (string.Equals(context.Request.Host.Host.ToString(), "localhost", StringComparison.InvariantCultureIgnoreCase))
{
await next.Invoke();
}
else
{
context.Request.Scheme = "https";
await next.Invoke();
}
});
//app.UseForwardedHeaders(new ForwardedHeadersOptions
//{
// ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
//});
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "ItemPerformance/{controller=Account}/{action=Login}/{id?}");
routes.MapRoute(
name: "default1",
template: "{controller=Home}/{action=Index}/{id?}");
});