App basics: HTTP, auth, dataLesson 5 of 11
How Logging In Works (Sessions, JWT, OIDC)
You type a password, or click Log in with Google, and the site knows who you are on every page after that. Follow how: password check → session cookie or JWT → OAuth 2.0 and OpenID Connect → tokens → 401 and 403.
WhoUnknown
CredentialPassword
Response—
RequestResponse / reportAppears in a later step
What you will learn
- Authentication (who you are) versus authorization (what you may do)
- Why passwords are stored as slow, salted hashes
- Session cookies versus stateless JWTs, and revoking each
- The OAuth 2.0 authorization code flow with PKCE, and what OIDC adds
- ID, access and refresh tokens, and 401 versus 403
Session cookie versus JWT
| Session cookie | JWT (self-contained token) | |
|---|---|---|
| What the client holds | A random ID with no meaning by itself | Signed claims (sub, exp, aud, …) anyone can read |
| How the server checks it | Looks the ID up in the session store | Verifies the signature with a key, no lookup |
| Revoking it | Delete the session record, effective at once | Wait for exp, or keep a denylist |
| Typical use | Classic server-rendered web apps | APIs, services that share one issuer, OIDC ID tokens |
| Main risk | Session store becomes a dependency | Long lifetimes, secrets put in the readable payload |
Three tokens from OIDC
| Token | Meant for | Format | Lifetime | Send it to |
|---|---|---|---|---|
| ID token | The app (client) | Always a JWT | Short | Nobody; the app checks it and reads who logged in |
| Access token | The API (resource server) | JWT or opaque string | Short (minutes to an hour) | The API, as Authorization: Bearer |
| Refresh token | The identity provider | Usually opaque | Long | Only the token endpoint |
Try it yourself
curl -s https://accounts.google.com/.well-known/openid-configuration | jq '{issuer, authorization_endpoint, token_endpoint, jwks_uri}' # OIDC discovery
curl -s https://www.googleapis.com/oauth2/v3/certs | jq '.keys[].kid' # Public keys (JWKS) that sign ID tokens
TOKEN='<paste a JWT>'
echo "$TOKEN" | cut -d. -f1 | tr '_-' '/+' | base64 -d; echo # Header: alg, kid (may warn about missing = padding)
echo "$TOKEN" | cut -d. -f2 | tr '_-' '/+' | base64 -d; echo # Payload: iss, sub, aud, exp. Readable by anyone, so not secret
curl -i -H "Authorization: Bearer $TOKEN" https://api.example.com/me # Watch for 200, 401 (+ WWW-Authenticate) or 403
date -r 1767225600 # Turn an exp value into a time (macOS; GNU: date -d @1767225600)
Check yourself
Further reading: OAuth 2.0 (RFC 6749) · PKCE (RFC 7636) · OAuth 2.0 Security Best Current Practice (RFC 9700) · JWT (RFC 7519) · OpenID Connect Core · OWASP Password Storage Cheat Sheet · OWASP Session Management Cheat Sheet · Kubernetes OIDC authentication · Permission Checks on One API Request (IAM) · Who Can Do What (RBAC)