Skip to content

Instantly share code, notes, and snippets.

@PadreSVK
Created December 16, 2019 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PadreSVK/8f6a400b07f2a20dfe8553968ef4bd6e to your computer and use it in GitHub Desktop.
Save PadreSVK/8f6a400b07f2a20dfe8553968ef4bd6e to your computer and use it in GitHub Desktop.
Register cookie auth in startup
///
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie();
services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
options.LoginPath = "/Account/Login";
options.AccessDeniedPath = "/Account/AccessDenied";
options.SlidingExpiration = true; // refresh auth cookie if existing is on half of lifetime
});
}
////////
app.UseAuthentication();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment