day-16

Django REST Framework Authentication and Permissions

This project demonstrates a complete implementation of JWT authentication and various permission levels in DRF.

Features implemented

Installation

  1. Install dependencies:
    pip install django djangorestframework djangorestframework-simplejwt
    
  2. Run migrations:
    python manage.py makemigrations
    python manage.py migrate
    
  3. Create a superuser (optional, for admin access):
    python manage.py createsuperuser
    
  4. Run the server:
    python manage.py runserver
    

Testing with Postman

  1. Import the drf_auth_collection.json file into Postman.
  2. Set the base_url variable (default: http://127.0.0.1:8000).
  3. Follow the sequence:
    • Register User: Create a new account.
    • Login: This will automatically save the access_token and refresh_token to Postman variables.
    • Get Profile: Verify you can access protected data.
    • Create Note: Test object-level permissions.

Authentication Errors handled

Project Structure

Please try visiting these specific API endpoints to see the DRF interface:

Public Demo: http://127.0.0.1:8000/api/auth/public/ Registration: http://127.0.0.1:8000/api/auth/register/ Login: http://127.0.0.1:8000/api/auth/login/