0
votes

I have a cookie based authentication in a server-side Balzor application.

I would like to show the user a popup when there is 5 minutes before their authentication expires.

Is the only way to keep track of the cookie timestamp through javascript or can I use something in asp.net core 3 authentication or is there possibly some other way?

Thanks in advance!

1
I think you can't track it in JavaScript as the cookie is encrypted. You might be able to know that in the back-end though if you call it. - juunas
I found this solution: DateTime.Parse((await Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.AuthenticateAsync(http.HttpContext)).Properties.Items[".expires"]) .Subtract(DateTime.Now) .TotalMinutes; - Fred
@Fred, how and from where do you have access to the HttpContext ? You've mentioned that you're using Blazor Server, which is a SignleR app; therefore, no HttpContext is available most of the time, if any, at all. Your solution is not going to work. - user12207343
If I inject it I get access to it. However I realize that it will still count down even though I work on the pages. @enet Do you have another suggestion? - Fred

1 Answers

0
votes

Instead of notifying users about their login session, you can keep session alive in asp.net core:

services.ConfigureApplicationCookie(config =>
{
    config.SlidingExpiration = true;// Add this
    config.ExpireTimeSpan = TimeSpan.FromMinutes(15);
    config.Cookie.HttpOnly = true;

});