This project demonstrates a simple authentication system using Django Rest Framework and JWT tokens. It includes endpoints for user signup, login, token testing, fetching user details, and an index endpoint.
- User Signup
- User Login
- JWT Authentication
- Token Verification
- Fetching User Details
- Python 3.6+
- Django 3.0+
- djangorestframework 3.11+
- djangorestframework-simplejwt
Clone the project
git clone https://github.com/Arnab-Afk/djangojwt
cd djangojwt
- Create a Virtual Environment
python -m venv venv
source venv/bin/activate
# On Windows, use `venv\Scripts\activate`
- Install Dependencies
pip install -r requirements.txt
- Apply Migrations
python manage.py migrate
- Run the Development Server
python manage.py runserver
POST /api/signup/
Response :
- Success: HTTP 200 OK with user data and tokens
- Failure: HTTP 400 Bad Request with error details
Parameter | Type | Description |
---|---|---|
username |
string |
Required. Unique username |
password |
String |
Required. Unique password |
email |
string |
Required. Unique Email |
POST /api/login/
Response :
- Success: HTTP 200 OK with user data and tokens
- Failure: HTTP 401 Unauthorized with error details
Parameter | Type | Description |
---|---|---|
username |
string |
Required. Unique username |
password |
String |
Required. Unique password |
GET /api/index/
Authorization: Bearer <access_token>
Response :
- Success: HTTP 200 OK with user data
- Failure: HTTP 401 Unauthorized with error details
GET /api/index/
You can run tests in test.rest file to test the endpoints using a REST client like VSCode REST Client:
### Signup a New User
POST /api/signup/
Content-Type: application/json
{
"username": "testuser",
"password": "testpassword",
"email": "testuser@example.com"
}
### Login with the New User
POST /api/login/
Content-Type: application/json
{
"username": "testuser",
"password": "testpassword"
}
### Test Token (Replace <access_token> with the token received from the login response)
GET /api/test-token/
Authorization: Bearer <access_token>
### Index API (Replace <access_token> with the token received from the login response)
GET /api/index/
Authorization: Bearer <access_token>
### Index API Unauthorized Access (Without Token)
GET /api/index/