Skip to content

Commit

Permalink
#115 chore: set max age of auth cookie to 2 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
joseantmazonsb committed Mar 17, 2022
1 parent 7b19b69 commit 98e07a3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Linguard/Web/Services/AuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class AuthenticationService : IAuthenticationService {
private readonly IJSRuntime _jsRuntime;
private readonly IAuthenticationCookieFormat _cookieFormat = AuthenticationCookieFormat.Default;
private const string JsNamespace = "authFunctions";

private static readonly TimeSpan AuthCookieExpireTimeSpan = TimeSpan.FromHours(2);

public AuthenticationService(ILogger logger, UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager,
AuthenticationStateProvider authenticationStateProvider,
IHostEnvironmentAuthenticationStateProvider hostAuthentication,
Expand Down Expand Up @@ -66,9 +67,9 @@ private ValueTask SetLoginCookie(ClaimsPrincipal principal) {
var ticket = new AuthenticationTicket(principal, default, _cookieFormat.Scheme);
var value = options.TicketDataFormat.Protect(ticket);
return _jsRuntime.InvokeVoidAsync($"{JsNamespace}.setCookie", _cookieFormat.Name,
value, options.ExpireTimeSpan.TotalSeconds);
value, AuthCookieExpireTimeSpan.TotalSeconds);
}

public async void Logout() {
var username = _signInManager.Context.User.Identity?.Name;
_logger.LogInformation($"Logging out user '{username}'...");
Expand Down

0 comments on commit 98e07a3

Please sign in to comment.