https://github.com/sahilverse/django-authentication-example
A comprehensive Django REST Framework authentication example implementing JWT (JSON Web Token) authentication with a custom user model. This project demonstrates best practices for building secure authentication systems in Django applications.
https://github.com/sahilverse/django-authentication-example
authentication django django-rest-framework postgresql swagger
Last synced: about 2 months ago
JSON representation
A comprehensive Django REST Framework authentication example implementing JWT (JSON Web Token) authentication with a custom user model. This project demonstrates best practices for building secure authentication systems in Django applications.
- Host: GitHub
- URL: https://github.com/sahilverse/django-authentication-example
- Owner: sahilverse
- License: mit
- Created: 2025-07-15T07:46:40.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-31T17:49:44.000Z (11 months ago)
- Last Synced: 2025-07-31T20:46:23.043Z (11 months ago)
- Topics: authentication, django, django-rest-framework, postgresql, swagger
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Django Authentication Example
A comprehensive Django REST Framework authentication example implementing JWT (JSON Web Token) authentication with a custom user model. This project demonstrates best practices for building secure authentication systems in Django applications.
### Features
- Custom User model using email as the primary identifier
- JWT (JSON Web Token) based authentication
- REST API endpoints for user management
- Email-based authentication
- CORS support for frontend integration
- API documentation with Swagger/OpenAPI
- Secure password handling
- PostgreSQL database support
### Technologies Used
- Django 5.2.4
- Django REST Framework 3.16.0
- djangorestframework-simplejwt 5.5.0
- PostgreSQL (via psycopg2-binary)
- django-cors-headers 4.7.0
- drf-yasg (for API documentation)
- python-decouple (for environment variables)
### Setup
1. Clone the repository:
```bash
git clone https://github.com/sahilverse/Django-Authentication-Example.git
cd Django-Authentication-Example
```
2. Create and activate a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
4. Create a `.env` file in the root directory with the following variables:
```
DJANGO_SECRET_KEY=your_secret_key_here
DEBUG=True
USE_POSTGRES=True
DB_ENGINE=your.db.engine.here
DB_NAME=your_db_name_here
DB_USER=your_db_user_here
DB_PASSWORD=your_db_password_here
DB_PORT=your_db_port_here
DB_HOST=your_db_host_here
```
5. Run migrations:
```bash
python manage.py migrate
```
6. Create a superuser:
```bash
python manage.py createsuperuser
```
7. Run the development server:
```bash
python manage.py runserver
```
### API Endpoints
- `POST /api/user/register/`: Register a new user
- `POST /api/user/login/`: Login and obtain JWT tokens
- `POST /api/user/token/refresh/`: Refresh JWT token
For complete API documentation, visit `/` or `/redoc/` after running the server.
### Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
### License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
### Acknowledgments
- Django documentation
- Django REST Framework documentation
- JWT authentication best practices