Memorise la connexion avec un cookie persistant
This commit is contained in:
@@ -119,6 +119,9 @@
|
||||
<p class="auth-modal-copy">
|
||||
L'authentification se fait maintenant directement dans l'application, sans redirection vers une page externe.
|
||||
</p>
|
||||
<p class="auth-modal-copy">
|
||||
La connexion reste memorisee sur ce navigateur pendant 30 jours.
|
||||
</p>
|
||||
|
||||
<div class="auth-modal-switch">
|
||||
<button class="@BuildModeButtonClass(AuthMode.Login)" type="button" @onclick="SwitchToLogin" disabled="@IsSubmitting">Se connecter</button>
|
||||
|
||||
@@ -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