Skip to content

A Django template for user authentication using JWT and Django REST Framework. Provides features like Swagger documentation, Flag based Performance monitoring and Profiling middlewares, Pre-commit hooks configuration, Testing etc

Notifications You must be signed in to change notification settings

madhvi-n/django-jwt-auth-template

Repository files navigation

Django CI

📜 Django JWT Authentication Template

This repository provides a boilerplate template for setting up JWT authentication in a Django project using the Django REST Framework (DRF). It's a starting point for building secure, token-based authentication systems for Django REST APIs.

🚀 Features

  • JWT Authentication: Implements secure JSON Web Token-based authentication.
  • Django REST Framework: Provides a robust API setup.
  • User Registration & Login: Supports authentication using email & password.
  • Token Refresh: Includes token refresh mechanism.
  • Swagger API Documentation: Auto-generated API docs for easy testing.
  • Monitoring & Debugging: Integrated Sentry Middleware for real-time error tracking and performance monitoring.
  • Performance Profiling: Planning to integrate cProfile Middleware for in-depth performance analysis.
  • Code Quality Tools: Pre-configured Pylint, Black, and Pre-commit hooks for maintaining clean code.
  • Type Checking & Import Sorting (optional): Uses Mypy for enhanced development.
  • Unit Testing: Uses pytest, pytest-django for testing

🛠 Prerequisites

  • Python 3.10+
  • Django 4.x or higher
  • Django REST Framework
  • PostgreSQL or SQLite (for database)
  • Virtual environment (recommended)

⚡ Installation

  1. Clone the repository:

    git clone https://github.com/madhvi-in/django-jwt-auth-template.git
    cd django-jwt-auth-template
  2. Set up a virtual environment:

    python -m venv venv
    source venv/bin/activate  # For macOS/Linux
    venv\Scripts\activate     # For Windows
  3. Install the dependencies:

    pip install -r requirements.txt
  4. Apply migrations:

    python manage.py migrate
  5. Create a superuser to access the admin panel:

    python manage.py createsuperuser
  6. Run the development server:

    python manage.py runserver
  7. Access the API at http://127.0.0.1:8000/api/v1/auth/.

  8. Set Up Google OAuth Credentials

    1. Go to the Google Cloud Console → Create a new project. 2 .Navigate to APIs & Services → Credentials.
    2. Click Create Credentials → OAuth 2.0 Client ID.
    3. Set Authorized redirect URIs:
    4. Save the Client ID and Client Secret.

🔥 API Endpoints

  • POST /api/v1/auth/register/: Register a new user.
  • POST /api/v1/auth/login/: Login with your credentials to get a JWT token.
  • POST /api/v1/auth/token/refresh/: Refresh the JWT token.
  • GET api/docs: API documentation

🎯 Running Pre-commit Hooks

This template comes with pre-configured pre-commit hooks to ensure code quality:

  1. Install pre-commit:

    pip install pre-commit
  2. Set up the hooks:

    pre-commit install && pre-commit install-hooks
  3. Run hooks manually for all files:

    pre-commit run --all-files

    The hooks will now automatically run before every commit.

⚙️ Build and run Docker using Environment variables

  1. You can pass the environment variables when building the Docker image:

    docker build --env-file .env -t django-jwt-auth-template .
    
  2. Then, when running the container, pass the environment variables to the container:

    docker run -d -p 8000:8000 --env-file .env --name django-auth django-jwt-auth-template

🎉 Happy coding! 🚀

About

A Django template for user authentication using JWT and Django REST Framework. Provides features like Swagger documentation, Flag based Performance monitoring and Profiling middlewares, Pre-commit hooks configuration, Testing etc

Topics

Resources

Stars

Watchers

Forks