Authentication
JWT (JSON Web Token)
JWT is a compact, URL-safe means of representing claims to be transferred between two parties. It is often used for authentication and information exchange.
Workflow!
- api/login > creates JWT
- save in localStorage < response with JWT
- request with signed JWT (placed in header) > validate JWT
SPA
Session
FE <> DB
- /login > store sessionĀ
- save cookie < response (session id)
- request with cookie > check session
- < response
Cons:
Vulnerable for CSRF - cross-site-request-forgery
Requires storage