This project implements a complete authentication system using Django REST Framework (DRF) and Simple JWT for token-based authentication. It allows users to register, log in, refresh their tokens, and access protected endpoints, making it ideal for applications requiring secure user authentication.
- User Registration: Create new users with custom user fields.
- User Login: Authenticate users using JWT tokens.
- Token Refresh: Refresh JWT tokens without re-authenticating.
- Secure Endpoints: Protect endpoints with JWT authentication.
- Postman Collection: Pre-configured Postman collection for easy API testing.
Follow the steps below to set up the project on your local machine.
- Python 3.x
- pip (Python package installer)
-
Clone the repository:
git clone https://github.com/abdurrahimcs50/django-rest-auth-api-jwt.git cd django-rest-auth-api-jwt
-
Create a virtual environment:
python -m venv env
-
Activate the virtual environment:
-
On Windows:
env\Scripts\activate
-
On Mac/Linux:
source env/bin/activate
-
-
Install the required dependencies:
pip install -r requirements.txt
-
Run migrations:
python manage.py makemigrations python manage.py migrate
-
Start the server:
python manage.py runserver
After running the server, the application will be available at
http://localhost:8000
.
The project includes a Postman Collection to easily test the authentication endpoints. Import the file django_auth_api_jwt.postman_collection
into Postman and start testing the authentication flow.
-
POST
/api/register/
- Register a new user.- Request Body:
{ "username": "user_name", "password": "user_password", "email": "user_email" }
- Request Body:
-
POST
/api/login/
- Log in and receive JWT tokens.-
Request Body:
{ "username": "user_name", "password": "user_password" }
-
Response:
{ "access": "JWT_ACCESS_TOKEN", "refresh": "JWT_REFRESH_TOKEN" }
-
-
POST
/api/token/refresh/
- Refresh the JWT token.-
Request Body:
{ "refresh": "JWT_REFRESH_TOKEN" }
-
Response:
{ "access": "NEW_JWT_ACCESS_TOKEN" }
-
Once the server is running, you can access the application in your web browser at http://localhost:8000
.
- Registration: Use the
POST /api/register/
endpoint to create a new user. - Login: Use the
POST /api/login/
endpoint to authenticate the user and retrieve the JWT tokens. - Refresh Token: Use the
POST /api/token/refresh/
endpoint to refresh the access token when expired.
We welcome contributions! If you find any bugs or have suggestions for improvements, feel free to create an issue or submit a pull request.
-
Fork the repository.
-
Clone your fork to your local machine:
git clone https://github.com/your_username/django-rest-auth-api-jwt.git cd django-rest-auth-api-jwt
-
Create a new branch for your changes:
git checkout -b feature/YourFeatureName
-
Make your changes and commit them:
git commit -m "Add a descriptive commit message"
-
Push your changes to your fork:
git push origin feature/YourFeatureName
-
Open a pull request to the main repository.
- Code Quality: Please ensure your code follows best practices and is well-documented.
- Testing: If applicable, include tests to verify your changes.
- Documentation: Update the README or other documentation if your changes affect usage.
This project is licensed under the MIT License. See the LICENSE file for more information.
For any questions or suggestions, feel free to reach out:
- Email: [email protected]
- LinkedIn: MD Abdur Rahim
- Website: www.rahim.com.bd