Sessions, Single Sign-On, and Logout

Logging a user in is the easy part; keeping them logged in — and, harder than anyone expects, logging them out — is where identity gets subtle. Sessions bridge stateless requests into a continuous identity, single sign-on shares that identity across apps, and single logout is a genuinely hard problem that most systems get partly wrong.

The protocols so far establish who a user is at login. But HTTP is stateless — each request stands alone — so something must remember that a user authenticated, across many requests and often many applications. That’s sessions, single sign-on (SSO), and the surprisingly thorny matter of logout. This post covers how authenticated identity persists after login, and why ending it cleanly is harder than starting it.

Sessions: persisting identity across stateless requests

After a user authenticates, you don’t want to re-authenticate them on every request. A session is the server-side (or token-based) memory that “this user is authenticated,” referenced on each subsequent request. Two dominant models:

The trade-off mirrors the tokens post: stateful is easy to revoke but needs shared storage; stateless scales but is hard to revoke. Many real systems combine them — a short-lived stateless access token for API calls plus a longer-lived, revocable server-side session or refresh token — to get scalability and revocability. The choice shapes both scaling and how cleanly you can log users out (below).

Cookies: the session’s vehicle, and its risks

Browser sessions ride on cookies, and cookie security is session security. The critical attributes:

The recurring browser tension from the tokens post reappears: cookies (HttpOnly) resist XSS token theft but need CSRF protection; tokens in JavaScript-accessible storage avoid CSRF but are exposed to XSS. There’s no free lunch — you pick a model and defend its weakness (HttpOnly cookies + CSRF tokens/SameSite is a common, solid choice). Session cookies must be HttpOnly, Secure, and SameSite-configured, with session IDs that are long, random, and regenerated on login (to prevent session fixation).

Single sign-on: one login, many apps

Single sign-on (SSO) is the payoff of federated identity (OIDC/SAML): a user authenticates once with the identity provider and can then access multiple applications without logging in again. The mechanism builds on the sessions above:

1. User logs into App A → authenticated at the IdP → IdP sets its OWN session
2. User visits App B → App B redirects to the IdP
3. IdP sees its existing session (user already authenticated) → issues a
   token/assertion to App B WITHOUT prompting for credentials again
4. User is logged into App B seamlessly

The key is that the IdP maintains its own session. Once you’ve authenticated to the IdP (via App A), it remembers you, so when App B redirects you there, the IdP recognizes the existing session and vouches for you immediately — no second login. This is why enterprise users log in once in the morning and access dozens of apps all day. Each app still gets its own proof (an ID token or SAML assertion) and establishes its own local session — SSO shares the IdP’s authentication, not the apps’ sessions.

Logout: the genuinely hard problem

Here’s the twist most systems underestimate: logging out is much harder than logging in, precisely because of sessions and SSO. Logging in creates one authenticated state; logging out must tear down several, and they don’t all live in one place:

The practical reality: complete logout across an SSO ecosystem is genuinely difficult, and many systems only do local logout, leaving the IdP session alive. Designing logout deliberately — deciding whether “log out” means this app, or everywhere, and implementing accordingly — is a real responsibility, especially for shared-device scenarios. Don’t assume “log out” cleanly ends everything; it usually doesn’t unless you engineer it to.

Designing sessions and logout well

Sessions and SSO are how login persists, and logout is where its difficulty concentrates. The final post pulls the whole series into the security practices that protect identity end to end.

Key takeaways

Further reading

Sources & References