Created
December 16, 2019 05:02
-
-
Save PadreSVK/8f6a400b07f2a20dfe8553968ef4bd6e to your computer and use it in GitHub Desktop.
Register cookie auth in startup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
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