Session Expiration
If the user session ends when the session cookie expires without explicitly triggering logout, there is most likely a need to clean up the server-side session data. To remove these expired records, there is an automatic cleanup mechanism that periodically scans for expired sessions. When these records are cleaned up, you can optionally notify the client that the session has ended via back-channel logout.
Expiration Configuration
Section titled “Expiration Configuration”The expiration configuration features can be configured with the server-side session options. It is enabled by default, but if you wish to disable it or change how often IdentityServer will check for expired sessions, you can.
For example, to change the interval:
builder.Services.AddIdentityServer(options => { options.ServerSideSessions.RemoveExpiredSessionsFrequency = TimeSpan.FromSeconds(60);}) .AddServerSideSessions();To disable:
builder.Services.AddIdentityServer(options => { options.ServerSideSessions.RemoveExpiredSessions = false;}) .AddServerSideSessions();Back-channel Logout
Section titled “Back-channel Logout”When the session cleanup job removes expired records, it will by default also trigger back-channel logout notifications to client applications participating in the session. You can use this mechanism to create an inactivity timeout that applies across all your client applications.
The ServerSideSessions.ExpiredSessionsTriggerBackchannelLogout flag enables this behavior, and it is on by default.
Session Renewal on Client Sign-in
Section titled “Session Renewal on Client Sign-in”When server-side sessions are enabled, the session cookie expiration can be extended beyond the originally configured
lifetime. This happens because IdentityServer calls SignInAsync whenever the session’s client list needs to be
updated, for example when a user signs into an additional client application. The SignInAsync call re-issues the
authentication cookie, which resets the expiration timer.
This is different from the behavior without server-side sessions, where the cookie expiration is set once at login and does not change when the user signs into additional clients.
If you need to enforce an absolute session duration regardless of client sign-in activity, you can configure
UserSsoLifetime on the client.
This setting forces the user to re-authenticate interactively after the specified number of seconds, even if they
have an active IdentityServer session. Combined with
AbsoluteRefreshTokenLifetime and setting
RefreshTokenExpiration to TokenExpiration.Absolute, you can align the refresh token expiration with the session
duration.
For example, to enforce a 12-hour absolute session and token lifetime on a client:
new Client{ ClientId = "interactive.confidential", // other settings...
UserSsoLifetime = (int)TimeSpan.FromHours(12).TotalSeconds, AbsoluteRefreshTokenLifetime = (int)TimeSpan.FromHours(12).TotalSeconds, RefreshTokenExpiration = TokenExpiration.Absolute}Configuring Server-Side Session Lifetime
Section titled “Configuring Server-Side Session Lifetime”If you need to change the default lifetime of server-side sessions, there are two ways to do so, depending on whether you’re using ASP.NET Core Identity or not.
The default session lifetime of 10 hours is inherited from the IdentityServerOptions.Authentication.CookieLifetime property.
When configuring IdentityServer, you can override this default:
builder.Services.AddIdentityServer(options => { options.Authentication.CookieLifetime = TimeSpan.FromMinutes(42);});When using ASP.NET Core Identity, the server-side session follows the lifetime of ASP.NET Core Identity’s session cookie, which is 14 days by default.
To change the lifetime, you need to reconfigure the application cookie using the ConfigureApplicationCookie extension method:
builder.Services.ConfigureApplicationCookie(options => { options.ExpireTimeSpan = TimeSpan.FromMinutes(42);});