A simple JWT token implementation using Flask to understand how authentication works in web applications.
This project shows how to:
- Create JWT tokens when users login
- Protect certain routes so only logged-in users can access them
- Verify tokens to check if users are authenticated
- Handle token expiration and errors
Install requirements: pip install flask pyjwt python-dotenv
Run the server: python app.py
Test the API:
- Get a token:
curl -X POST http://127.0.0.1:5000/login
-H "Content-Type: application/json"
-d '{"username":"alice","password":"password123"}' - Use the token:
curl -X GET http://127.0.0.1:5000/protected
-H "Authorization: Bearer YOUR_TOKEN_HERE"
- app.py - Main Flask application with routes
- jwt_utils.py - Functions to create and verify JWT tokens
- auth_decorators.py - Protection for routes that need authentication
This is a beginner-friendly project to understand:
- How JWT tokens work
- Basic web authentication
- Flask route protection
- API development fundamentals
- Perfect for learning web development and authentication concepts!