Step 7 of 11
JWT/sessions, OAuth concepts, input validation, common vulnerabilities (OWASP)
JWT, OAuth, authorization policies — security patterns สำหรับ .NET backend
Authentication answers "who are you?" Authorization answers "what can you do?" They are different things. Confusing them causes security holes.
Loading diagram...
Pros: Server can revoke sessions instantly. Session data stays server-side. Cons: Hard to scale across multiple servers (need shared session store). Stateful.
Pros: Stateless. Easy to scale. Works across services. Cons: Cannot revoke instantly (token is valid until expiry). Token contains data that can get stale.
A JWT has three parts separated by dots: header.payload.signature
xxxxx.yyyyy.zzzzz
Header — Algorithm and token type:
{
"alg": "HS256",
"typ": "JWT"
}
Payload — Claims (data). Do not put secrets here:
{
"sub": "user-42",
"name": "Alice",
"role": "admin",
"exp": 1700000000
}
Signature — Proves the token was not tampered with:
HMACSHA256(base64(header) + "." + base64(payload), secret_key)
JWT is:
JWT is not:
| Need | Use |
|---|---|
| Instant revocation | Server-side sessions |
| Scale across services | JWT |
| Simple app, one server | Sessions |
| Microservices / API | JWT |
| Both | JWT + refresh tokens with a revocation list |
iss (issuer) and aud (audience).