Memorise la connexion avec un cookie persistant
This commit is contained in:
@@ -42,10 +42,12 @@ builder.Services
|
||||
{
|
||||
options.Cookie.Name = "chesscubing.auth";
|
||||
options.Cookie.HttpOnly = true;
|
||||
options.Cookie.IsEssential = true;
|
||||
options.Cookie.SameSite = SameSiteMode.Lax;
|
||||
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
|
||||
options.Cookie.MaxAge = TimeSpan.FromDays(30);
|
||||
options.SlidingExpiration = true;
|
||||
options.ExpireTimeSpan = TimeSpan.FromDays(7);
|
||||
options.ExpireTimeSpan = TimeSpan.FromDays(30);
|
||||
options.Events = new CookieAuthenticationEvents
|
||||
{
|
||||
OnRedirectToLogin = context =>
|
||||
@@ -526,6 +528,7 @@ static string? NormalizeOptionalValue(string? value, string fieldName, int maxLe
|
||||
|
||||
static async Task SignInAsync(HttpContext httpContext, KeycloakUserInfo userInfo)
|
||||
{
|
||||
var issuedAt = DateTimeOffset.UtcNow;
|
||||
var claims = new List<Claim>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(userInfo.Subject))
|
||||
@@ -567,7 +570,8 @@ static async Task SignInAsync(HttpContext httpContext, KeycloakUserInfo userInfo
|
||||
{
|
||||
IsPersistent = true,
|
||||
AllowRefresh = true,
|
||||
ExpiresUtc = DateTimeOffset.UtcNow.AddDays(7),
|
||||
IssuedUtc = issuedAt,
|
||||
ExpiresUtc = issuedAt.AddDays(30),
|
||||
});
|
||||
|
||||
httpContext.User = principal;
|
||||
|
||||
Reference in New Issue
Block a user