Skip to content

Commit 2e2bfa0

Browse files
authored
Merge pull request #769 from DuendeSoftware/wca/idsrv-serverside-sessions
Added section on how to configure server-side session lifetime
2 parents f05c369 + 486f05e commit 2e2bfa0

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/content/docs/identityserver/ui/server-side-sessions/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ redirect_from:
99
- /identityserver/v7/ui/server_side_sessions/
1010
---
1111

12-
:::tip
13-
Added in Duende IdentityServer 6.1
14-
:::
12+
<span data-shb-badge data-shb-badge-variant="default">Added in 6.1</span>
1513

1614
When a user logs in interactively, their authentication session is managed by the ASP.NET Core authentication system,
1715
and more specifically the cookie authentication handler.

src/content/docs/identityserver/ui/server-side-sessions/session-expiration.md renamed to src/content/docs/identityserver/ui/server-side-sessions/session-expiration.mdx

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ redirect_from:
99
- /identityserver/v7/ui/server_side_sessions/session_expiration/
1010
---
1111

12-
If the user session ends when the session cookie expires without explicitly triggering logout, there is most likely the
12+
import { Code } from "astro/components";
13+
import { Tabs, TabItem } from "@astrojs/starlight/components";
14+
15+
If the user session ends when the session cookie expires without explicitly triggering logout, there is most likely a
1316
need to clean up the server-side session data.
14-
In order to remove these expired records, there is an automatic cleanup mechanism that periodically scans for expired
17+
To remove these expired records, there is an automatic cleanup mechanism that periodically scans for expired
1518
sessions.
1619
When these records are cleaned up, you can optionally notify the client that the session has ended via back-channel
1720
logout.
@@ -25,7 +28,7 @@ sessions, you can.
2528

2629
For example, to change the interval:
2730

28-
```cs
31+
```csharp
2932
// Program.cs
3033
builder.Services.AddIdentityServer(options => {
3134
options.ServerSideSessions.RemoveExpiredSessionsFrequency = TimeSpan.FromSeconds(60);
@@ -35,7 +38,7 @@ builder.Services.AddIdentityServer(options => {
3538

3639
To disable:
3740

38-
```cs
41+
```csharp
3942
// Program.cs
4043
builder.Services.AddIdentityServer(options => {
4144
options.ServerSideSessions.RemoveExpiredSessions = false;
@@ -51,3 +54,37 @@ to client applications participating in the session. You can use this mechanism
5154
an [inactivity timeout](/identityserver/ui/server-side-sessions/inactivity-timeout/) that applies across all your client applications.
5255

5356
The `ServerSideSessions.ExpiredSessionsTriggerBackchannelLogout` flag enables this behavior, and it is on by default.
57+
58+
### Configuring Server-Side Session Lifetime
59+
60+
If you need to change the default lifetime of server-side sessions, there are two ways to do so, depending on whether
61+
you're using ASP.NET Core Identity or not.
62+
63+
<Tabs>
64+
<TabItem label="Default behavior">
65+
The default session lifetime of 10 hours is inherited from the [`IdentityServerOptions.Authentication.CookieLifetime`](/identityserver/reference/options/#authentication) property.
66+
When configuring IdentityServer, you can override this default:
67+
68+
<Code
69+
lang="csharp"
70+
title="Program.cs"
71+
code={`
72+
builder.Services.AddIdentityServer(options => {
73+
options.Authentication.CookieLifetime = TimeSpan.FromMinutes(42);
74+
});`}
75+
/>
76+
</TabItem>
77+
<TabItem label="ASP.NET Core Identity">
78+
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.
79+
To change the lifetime, you need to reconfigure the application cookie using the `ConfigureApplicationCookie` extension method:
80+
81+
<Code
82+
lang="csharp"
83+
title="Program.cs"
84+
code={`
85+
builder.Services.ConfigureApplicationCookie(options => {
86+
options.ExpireTimeSpan = TimeSpan.FromMinutes(42);
87+
});`}
88+
/>
89+
</TabItem>
90+
</Tabs>

0 commit comments

Comments
 (0)