简体   繁体   中英

Web site keeps on refreshing due to cookie expiration and authentication issue

Below is the configuration and sign in code I have used.But if I have not signed out from the application, after some hours if I try to sign in It will keep on refreshing

Startup.cs has below code

 public void ConfigureAuth(IAppBuilder app)
        {       app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                ExpireTimeSpan = TimeSpan.FromHours(4),
                SlidingExpiration = true
            });
            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = ClientId,
                    Authority = Authority,
                    RedirectUri = redirectUri,
                    PostLogoutRedirectUri = postLogoutRedirectUri,
                    Scope = OpenIdConnectScope.OpenIdProfile,
                    ResponseType = OpenIdConnectResponseType.IdToken,
                    TokenValidationParameters = new TokenValidationParameters()
                    {
                        ValidateIssuer = false
                    },
  
                    Notifications = new OpenIdConnectAuthenticationNotifications
                    {
                        AuthenticationFailed = OnAuthenticationFailed
                    },
                    CookieManager = new SameSiteCookieManager(new SystemWebCookieManager())
                }
            );
}

signin page

public void SignIn()
    {
         if (!Request.IsAuthenticated)
        {
            HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties 
            { RedirectUri = "/", IsPersistent = true },
                OpenIdConnectAuthenticationDefaults.AuthenticationType);
            }
     }

To start: UseOpenIdConnectAuthentication is obsolete. Configure OpenIdConnect authentication with AddAuthentication().AddOpenIdConnect in ConfigureServices. See https://go.microsoft.com/fwlink/?linkid=845470 for more details.

So at least I'd strongly advice to upgrade to the latest supported standards.

Besides the fact that there is too little information to determine what might be wrong, it might be a good idea to check out the example regarding OIDC: https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM