๐ API Authentication โ Visual Flows
๐ Try the interactive playground
1๏ธโฃ Basic Auth
2๏ธโฃ API Key Auth
3๏ธโฃ JWT Auth (2-step)
๐ HTTP status codes used in this API
| Code | Meaning | Example |
| 200 | โ
OK | Successful auth |
| 400 | โ ๏ธ Bad Request | Missing username/password in /login |
| 401 | ๐ Unauthorized | Wrong password, bad API key, expired JWT |
| 404 | ๐ซ Not Found | Unknown URL |
| 405 | ๐ซ Method Not Allowed | GET on /login (POST only) |
| 500 | ๐ฅ Server Error | Unhandled exception |
๐งช Try it (curl)
# Basic
curl -u alice:password123 http://140.245.218.78/basic
# API Key
curl -H "X-API-Key: student123" http://140.245.218.78/apikey
# JWT โ step 1: login
curl -X POST http://140.245.218.78/login \
-H "Content-Type: application/json" \
-d '{"username":"alice","password":"password123"}'
# JWT โ step 2: use token
curl -H "Authorization: Bearer <TOKEN>" http://140.245.218.78/jwt
# Peek inside a JWT
curl -X POST http://140.245.218.78/debug/jwt \
-H "Content-Type: application/json" \
-d '{"token":"<TOKEN>"}'
โ Failure cases (learn what "wrong" looks like)
# Wrong password โ 401
curl -u alice:WRONG http://140.245.218.78/basic
# Missing header โ 401
curl http://140.245.218.78/basic
# Bad API key โ 401
curl -H "X-API-Key: nope" http://140.245.218.78/apikey
# Tampered JWT โ 401
curl -H "Authorization: Bearer eyJhbGci.TAMPERED.xxx" http://140.245.218.78/jwt
# No Bearer prefix โ 401
curl -H "Authorization: <TOKEN>" http://140.245.218.78/jwt