cookie configuration

This commit is contained in:
john 2025-05-18 01:30:45 +02:00
parent b4edb6ae83
commit e3c95eb109
5 changed files with 22 additions and 8 deletions

View file

@ -0,0 +1,7 @@
namespace Femto.Api.Auth;
public class CookieSettings
{
public bool SameSite { get; set; }
public bool Secure { get; set; }
}

View file

@ -15,7 +15,8 @@ internal class SessionAuthenticationHandler(
ILoggerFactory logger,
UrlEncoder encoder,
IAuthModule authModule,
CurrentUserContext currentUserContext
CurrentUserContext currentUserContext,
IOptions<CookieSettings> cookieOptions
) : AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder)
{
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
@ -38,7 +39,7 @@ internal class SessionAuthenticationHandler(
var identity = new ClaimsIdentity(claims, this.Scheme.Name);
var principal = new ClaimsPrincipal(identity);
this.Context.SetSession(result.Session);
this.Context.SetSession(result.Session, cookieOptions.Value);
currentUserContext.CurrentUser = new CurrentUser(result.UserId, result.Username);
return AuthenticateResult.Success(