Skip to content
This repository was archived by the owner on Aug 10, 2026. It is now read-only.

Commit 0a8b371

Browse files
committed
Added JWT app prompt
1 parent 88261a1 commit 0a8b371

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎Chapter-4/JWT_security.md‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
I have a beginner FastAPI Employee Management app and I want to upgrade it with JWT authentication for teaching purposes.
2+
3+
Please modify the app so students can learn:
4+
1. login
5+
2. password verification
6+
3. JWT creation
7+
4. token validation
8+
5. role-based access control
9+
10+
Requirements:
11+
- FastAPI app
12+
- one-file implementation preferred
13+
- hardcoded users only for now
14+
- admin and user role
15+
- JWT Bearer token auth
16+
- protect employee routes
17+
- beginner-friendly code and explanations
18+
19+
Hardcoded users:
20+
- admin / admin123 / role=admin
21+
- user / user123 / role=user
22+
23+
JWT requirements:
24+
- include username and role in token
25+
- include expiration
26+
- validate signature and expiration
27+
- return 401 for bad token/login
28+
- return 403 for insufficient role
29+
30+
Route access:
31+
- GET /employees → admin or user
32+
- POST /employees → admin only
33+
- PUT /employees/{id} → admin only
34+
- DELETE /employees/{id} → admin only
35+
36+
Output required:
37+
- pip install commands
38+
- full code
39+
- run instructions
40+
- sample login curl
41+
- sample protected route curl
42+
- simple explanation of the JWT authentication flow
43+
44+
Keep it simple enough for fresh graduate students to understand and maintain.

0 commit comments

Comments
 (0)