Access & APIsUpdated 2026-11-20

Authentication

Sessions, argon2id, OIDC and TOTP: the defaults I use for a multi-tenant web app, and what I never build myself.

The ID check. It confirms who you are before you see your own things.

That is authentication. It answers who you are. A separate step, authorisation, decides what you may do once the guard knows your name. A multi-tenant product needs both, plus a model of which organisation you belong to.

How it works

The defaults I start from for a web app:

Code
Sign in → verify password (argon2id) → MFA challenge → create session row
Cookie: HttpOnly · Secure · SameSite=Lax · short idle timeout
Each request → load session → user + active organisation + role
Sensitive change (password, MFA, role) → rotate session id, revoke others

The choices behind it:

  • Sessions. A server-side session, where the cookie holds an id and the state is a database row. It is easy to revoke. A signed token scales without a lookup but is hard to revoke before it expires.
  • Passwords. argon2id, with a check against breached passwords.
  • Social login. OAuth 2.0 with OIDC, using PKCE and state checks.
  • MFA. TOTP apps with recovery codes. SMS only as a fallback. Passkeys as an option.

The concerns that are easy to miss

  • Session rotation. Issue a new session id after login and after any privilege change, to block session fixation.
  • Limits on sign-in. Put rate limits on sign-in, reset and verification, and use generic error messages so the response does not reveal which accounts exist.
  • The organisation model. Users link to organisations through a membership that carries a role. Check permissions on the server for every action, never only in the interface.
  • Support access. If staff can view as a user, require a reason, show a banner, time-limit it, prefer read-only and audit every action.
  • Email links. Reset and verification tokens are short-lived, single-use and stored hashed.
  • Libraries. Use a maintained library for the crypto. Do not hand-roll it.

This sits next to multi-tenancy: authentication says who you are and which organisation is active, and the database rules keep you inside it.

Why revocation drives the choice

Most arguments about sessions and tokens come down to one question: how fast must a login be cancelled? An owner removes an employee, a phone is lost, a password leaks. With a server-side session, deleting the row ends it on the next request. With a signed token, the token stays valid until it expires unless you keep a deny list, and a deny list brings back the lookup you were avoiding. Write down the revocation requirement first, then choose the cheapest design that meets it.

Where I used it

IMS uses argon2id for passwords, TOTP for a second factor, OIDC for social sign-in and Turnstile on the auth side. IMS is in progress and I make no production claim, so this is the design in source and not a proven result.

In my POS SaaS design, sessions use rotating refresh tokens with reuse detection. I have not written a trade-off for that choice, so I will not invent one. POS is early-stage.

I haven't shipped anything beyond that in a public project yet.

Trade-offs

BenefitCost
Server sessions are revocableA database or cache lookup on each request
Tokens scale without lookupsHard to revoke, larger cookies
Mandatory MFA stops most takeoversMore sign-up friction and more support
Hosted auth is fast to shipVendor lock-in and per-user pricing

Two rules sit behind the table. First, I do not build password storage, OAuth flows or MFA from scratch. A vetted library gets that right more often than I will. Second, I avoid token-only sessions when the product needs instant revocation, for example when an owner removes an employee and expects them out at once.

A useful rule: make sign-in boring and revocable, and make the server decide permissions on every request.