A Django-based authentication system with cookie-based authentication, OTP verification, and Swagger documentation.
- User Registration with Email Verification (OTP)
- Cookie-based Authentication
- Swagger API Documentation
- CSRF Protection
- Secure Cookie Configuration
- Interactive HTML Test Interface
- Python 3.x
- Django 4.2.x
- Django REST Framework
- drf-yasg (for Swagger)
- django-cors-headers
- Clone the repository
- Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Apply migrations:
python manage.py migrate
- Run the development server:
python manage.py runserver
Access the Swagger documentation at:
- http://localhost:8000/swagger/ (Swagger UI)
- http://localhost:8000/redoc/ (ReDoc UI)
-
Register User
- URL:
/api/auth/register/ - Method: POST
- Body:
{ "email": "user@example.com", "password": "secure_password", "password2": "secure_password" }
- URL:
-
Verify OTP
- URL:
/api/auth/verify-otp/ - Method: POST
- Body:
{ "email": "user@example.com", "otp": "123456" }
- URL:
-
Login
- URL:
/api/auth/login/ - Method: POST
- Body:
{ "email": "user@example.com", "password": "secure_password" }
- URL:
-
Logout
- URL:
/api/auth/logout/ - Method: POST
- Authentication: Required
- URL:
-
Get User Profile
- URL:
/api/auth/profile/ - Method: GET
- Authentication: Required
- URL:
-
Resend OTP
- URL:
/api/auth/resend-otp/ - Method: POST
- Body:
{ "email": "user@example.com" }
- URL:
The API uses cookie-based authentication. After successful login, the server will set an HTTP-only cookie that will be automatically included in subsequent requests.
For POST, PUT, PATCH, and DELETE requests, include the CSRF token in the header: