Most of the questions I found here on SO have the opposite problem - i.e. the session does not slide. My problem is that it never seems to stop.
The only way I am able to get automatically logged out for an expired session is if I make the window absolute (SlidingExpiration = false
).
I'm using IdentityServer 4 with ASP.NET Identity for the backing user store.
The configuration of the cookie which I currently have is:
services.AddIdentity<IdpUser, IdentityRole<int>>()
.AddEntityFrameworkStores<IdpDbContext>()
.AddDefaultTokenProviders();
// Note ASP.NET identity uses a cookie called "Identity.Application"
services.ConfigureApplicationCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(15); // for testing purposes
options.SlidingExpiration = true;
});
Our client is a Vuejs app using oidc-client.js to manage the tokens.
I've reduced all of the lifetimes in the client-configuration down to 300s (including the access token). So, it gets a new access_token every 300s.
I would expect that if I logged in, walked away for more than 15 minutes and came back, I would have been logged out. But this is not the case. It keeps getting new tokens.
Even if I refresh the whole page, I am still not logged out.
Following further investigation, I believe the constant polling which oidc-client.js
does is extending the sliding window for the authentication cookie. This is a theory based on observed behavior. I increased the duration of the access_token lifetime such that it was longer than the authentication cookie. In this case, the user was logged out after the auth cookie expired. Presumably because the client did not request another access_token in that time (and thereby extending the window).
So it seems that the sliding window will keep sliding until the SlidingRefreshTokenLifetime
is reached, which defaults at around 15 days.
Is reducing the SlidingRefreshTokenLifetime
down to something like 3 hours likely to be my answer?
Thanks