IAM interview questions · Fundamentals
How do sessions and tokens relate after a user logs in?
In plain wordsAfter the login you get a wristband (session) for the app, while the IdP keeps its own wristband for SSO. Tokens are tickets for the APIs.
How it works
After a successful login there are usually three things: the IdP session (cookie on the IdP domain, enables SSO), the application session (cookie on the app domain, or server-side session) and tokens (access token for APIs, refresh token to get new ones).
Each has its own lifetime. Short access tokens limit damage if stolen; refresh tokens keep the user logged in without asking again. Idle timeout and absolute timeout should be defined separately.
Session cookies need Secure, HttpOnly and SameSite, and must be regenerated after login to avoid session fixation. For SPAs, the safest pattern today is a backend-for-frontend that keeps tokens server side.
A concrete example
A banking app: IdP session 8 hours, app session 15 minutes idle and 12 hours absolute, access token 5 minutes, refresh token rotated on every use. If the phone is stolen while unlocked, the attacker has at most 15 idle minutes and the bank can revoke the refresh token family remotely.
See it in action: a shared computer
Mistakes to avoid
- Storing tokens in localStorage, readable by any XSS.
- Assuming that disabling the user ends all sessions instantly.
They may also ask you
- How would you force logout of a user everywhere?
- Cookies or tokens for a single-page application?
- Go deeper
- Session →
- Refresh token →