Backend Authentication
Purpose
Establish the caller's identity safely: credential handling, session/token strategy, lifecycle (issue → refresh → revoke), and the account flows around it. Authentication answers "who is this?" — what they may do is backend-authorization.
When to Use
- When designing or reworking login/signup/session handling.
- Not for role/permission/ownership decisions (authorization skills) or abuse throttling (
rate-limiting, captcha-abuse-prevention) — those wrap these flows but are distinct concerns.
Inputs
- Client list (web/mobile/third-party) and their session constraints.
- Requirements: SSO/OAuth providers, MFA/OTP, session duration policy.
Discovery Questions
- Which clients authenticate, and can they hold secrets (browser vs mobile vs server)?
- Sessions (server-state, revocable) or JWTs (stateless, revocation harder) — what does the system actually need?
- What account flows are in scope: signup, verify, password reset, OTP, MFA?
- What forces logout-everywhere (password change, breach response)?
Responsibilities
Credential input rules (email normalization, password policy, confirm match) come from ../../auth-form-validation — one schema, enforced on the server too.
Store credentials only as strong adaptive hashes (bcrypt/argon2); never reversible, never logged.
Choose session vs JWT on requirements: revocability, horizontal scale, third-party consumption — and record the trade-off. Short-lived access + refresh rotation when JWTs are chosen; httpOnly/secure/sameSite cookies for browsers.
Define lifecycle: issuance, expiry, refresh rotation (reuse detection), revocation, logout (and logout-all).
Design account flows: signup + verification, password reset (single-use, expiring, no account enumeration), OTP (expiring, attempt-limited).
Hand abuse protection of these public flows to rate-limiting + captcha-abuse-prevention; hand post-login access decisions to backend-authorization.
Required Workflow
- Gather clients, providers, and session requirements.
- Choose the credential + session/token strategy; record trade-offs.
- Define token/session lifecycle including revocation and logout.
- Design each account flow with its failure and abuse cases.
- Specify tests: wrong password, expired/tampered token, reused refresh token, reset-token reuse, enumeration responses.
Decision Rules
- Browsers get httpOnly cookies, not localStorage tokens.
- If instant revocation is a hard requirement, pure stateless JWT is the wrong tool — use sessions or a denylist and record the cost.
- Responses to login/reset must not reveal whether an account exists.
- MFA/OTP secrets and recovery codes are credentials — hash/encrypt accordingly.
Rules
- Server verifies identity on every request; client-held state is a hint, not proof.
- Secrets (signing keys, provider credentials) follow
../../environment-audit / backend-security.
- Never invent crypto; use vetted libraries and record versions.
Anti-Patterns
- Confusing authentication with authorization ("logged in" ⇒ "allowed").
- Long-lived access tokens with no refresh/rotation story.
- Password reset links that don't expire or work multiple times.
- Different error messages for "no such user" vs "wrong password."
- Storing plaintext or fast-hash (MD5/SHA1) passwords.
Validation Checklist
Definition of Done
A recorded authentication design — credential handling, session/token strategy with trade-offs, full lifecycle, account flows with enumeration resistance — with negative tests specified and authorization explicitly out of scope.
Related Skills
backend-authorization, role-permission-design, ownership-authorization, rate-limiting, captcha-abuse-prevention, backend-security, email-notifications (verification/reset mail), ../../security-review.
Related Knowledge
../../../knowledge/ (identity providers, session policy).
Related References
../../../references/backend/auth/ (flow notes, when populated).
Context Loading Guidance
- Requires: client list, provider/MFA requirements, session policy.
- Does not require: role models, endpoint inventory, database internals.
- May load:
backend-authorization (hand-off), rate-limiting (flow protection).
- Stop when: the authentication design + negative tests are recorded.
Token Efficiency Guidance
Design from the client/flow list; a lifecycle table (event → token effect) carries more than prose. Delegate authorization and abuse throttling instead of restating them.
1---2name: backend-authentication3description: Use to plan backend authentication (who the caller is) — credential storage (hashing), sessions vs JWT, token lifecycle/refresh/revocation, logout, and account flows (signup, password reset, OTP). Authentication is not authorization.4---56# Backend Authentication78## Purpose910Establish the caller's identity safely: credential handling, session/token strategy, lifecycle (issue → refresh → revoke), and the account flows around it. **Authentication answers "who is this?" — what they may do is `backend-authorization`.**1112## When to Use1314- When designing or reworking login/signup/session handling.15- **Not** for role/permission/ownership decisions (authorization skills) or abuse throttling (`rate-limiting`, `captcha-abuse-prevention`) — those wrap these flows but are distinct concerns.1617## Inputs1819- Client list (web/mobile/third-party) and their session constraints.20- Requirements: SSO/OAuth providers, MFA/OTP, session duration policy.2122## Discovery Questions2324- Which clients authenticate, and can they hold secrets (browser vs mobile vs server)?25- Sessions (server-state, revocable) or JWTs (stateless, revocation harder) — what does the system actually need?26- What account flows are in scope: signup, verify, password reset, OTP, MFA?27- What forces logout-everywhere (password change, breach response)?2829## Responsibilities3031- Credential **input rules** (email normalization, password policy, confirm match) come from `../../auth-form-validation` — one schema, enforced on the server too.3233- Store credentials only as strong adaptive hashes (bcrypt/argon2); never reversible, never logged.34- Choose **session vs JWT** on requirements: revocability, horizontal scale, third-party consumption — and record the trade-off. Short-lived access + refresh rotation when JWTs are chosen; httpOnly/secure/sameSite cookies for browsers.35- Define lifecycle: issuance, expiry, refresh rotation (reuse detection), revocation, logout (and logout-all).36- Design account flows: signup + verification, password reset (single-use, expiring, no account enumeration), OTP (expiring, attempt-limited).37- Hand abuse protection of these public flows to `rate-limiting` + `captcha-abuse-prevention`; hand post-login access decisions to `backend-authorization`.3839## Required Workflow40411. Gather clients, providers, and session requirements.422. Choose the credential + session/token strategy; record trade-offs.433. Define token/session lifecycle including revocation and logout.444. Design each account flow with its failure and abuse cases.455. Specify tests: wrong password, expired/tampered token, reused refresh token, reset-token reuse, enumeration responses.4647## Decision Rules4849- Browsers get httpOnly cookies, not localStorage tokens.50- If instant revocation is a hard requirement, pure stateless JWT is the wrong tool — use sessions or a denylist and record the cost.51- Responses to login/reset must not reveal whether an account exists.52- MFA/OTP secrets and recovery codes are credentials — hash/encrypt accordingly.5354## Rules5556- Server verifies identity on every request; client-held state is a hint, not proof.57- Secrets (signing keys, provider credentials) follow `../../environment-audit` / `backend-security`.58- Never invent crypto; use vetted libraries and record versions.5960## Anti-Patterns6162- Confusing authentication with authorization ("logged in" ⇒ "allowed").63- Long-lived access tokens with no refresh/rotation story.64- Password reset links that don't expire or work multiple times.65- Different error messages for "no such user" vs "wrong password."66- Storing plaintext or fast-hash (MD5/SHA1) passwords.6768## Validation Checklist6970- [ ] Credential storage uses adaptive hashing.71- [ ] Session/JWT choice recorded with trade-offs.72- [ ] Lifecycle covers refresh rotation, revocation, logout(-all).73- [ ] Account flows designed with enumeration resistance.74- [ ] Abuse protection delegated to rate-limiting/CAPTCHA skills.75- [ ] Negative tests specified (tampered/expired/reused tokens).7677## Definition of Done7879A recorded authentication design — credential handling, session/token strategy with trade-offs, full lifecycle, account flows with enumeration resistance — with negative tests specified and authorization explicitly out of scope.8081## Related Skills8283`backend-authorization`, `role-permission-design`, `ownership-authorization`, `rate-limiting`, `captcha-abuse-prevention`, `backend-security`, `email-notifications` (verification/reset mail), `../../security-review`.8485## Related Knowledge8687`../../../knowledge/` (identity providers, session policy).8889## Related References9091`../../../references/backend/auth/` (flow notes, when populated).9293## Context Loading Guidance9495- **Requires:** client list, provider/MFA requirements, session policy.96- **Does not require:** role models, endpoint inventory, database internals.97- **May load:** `backend-authorization` (hand-off), `rate-limiting` (flow protection).98- **Stop when:** the authentication design + negative tests are recorded.99100## Token Efficiency Guidance101102Design from the client/flow list; a lifecycle table (event → token effect) carries more than prose. Delegate authorization and abuse throttling instead of restating them.