Skip to main content

A reusable Django package for quick login and signup endpoints with optional JWT authentication

Project description

Django Quick Auth

PyPI version Python Versions License

A reusable Django package that provides quick and easy authentication endpoints for login and signup functionality with optional JWT authentication support. Simplify your Django project's authentication system without writing boilerplate code.

Features

  • Ready-to-use login and signup endpoints
  • Optional JWT authentication support
  • Customizable user model
  • Easy integration with existing Django projects
  • Fully configurable through settings

Installation

pip install tc-django-quick-auth

Important Note: While the package is installed as tc-django-quick-auth, you'll reference it in your Python code and Django settings as django_quick_auth. This follows Python package conventions where PyPI package names use hyphens, but Python module names use underscores.

Configuration

1. Add to INSTALLED_APPS

Add django_quick_auth to your INSTALLED_APPS in your Django project's settings:

INSTALLED_APPS = [
    # ...
    "rest_framework",
    "rest_framework_simplejwt",
    'django_quick_auth',
]

2. Configure User Model (Optional)

If you want to use the custom QuickAuthUser model provided by this package, add this to your settings:

AUTH_USER_MODEL = 'django_quick_auth.QuickAuthUser'

Note: If you're adding this to an existing project that already has migrations with the default Django User model, you'll need to create a migration strategy or start with a fresh database.

3. URL Configuration

Include the authentication URLs in your project's urls.py:

from django.urls import path, include

urlpatterns = [
    # ...
    path('api/auth/', include('django_quick_auth.urls')),
    # ...
]

4. JWT Configuration (Optional)

If you want to use JWT authentication, configure the JWT settings in your project settings:

# JWT Settings
QUICK_AUTH = {
    'USE_JWT': True,
    'JWT_SECRET_KEY': 'your-secret-key',
    'JWT_ALGORITHM': 'HS256',
    'JWT_EXPIRATION_DELTA': 24 * 60 * 60,  # Token expiry time in seconds (24 hours)
    'JWT_REFRESH_EXPIRATION_DELTA': 7 * 24 * 60 * 60,  # Refresh token expiry time in seconds (7 days)
}

5. Run Migrations

After configuring your settings, run migrations to create the necessary database tables:

python manage.py makemigrations
python manage.py migrate

Usage

Authentication Endpoints

Once configured, the package provides the following endpoints:

  • POST /api/auth/signup/ - Register a new user

    {
      "username": "newuser",
      "email": "user@example.com",
      "password": "securepassword"
    }
    
  • POST /api/auth/login/ - Login with existing credentials

    {
      "username": "existinguser",
      "password": "securepassword"
    }
    

JWT Authentication

If JWT is enabled, successful login/signup will return:

{
  "token": "your.jwt.token",
  "refresh_token": "your.refresh.token",
  "user": {
    "id": 1,
    "username": "username",
    "email": "user@example.com"
  }
}

Customization

Custom User Fields

You can extend the QuickAuthUser model by creating your own model that inherits from it:

from django_quick_auth.models import QuickAuthUser
from django.db import models

class MyCustomUser(QuickAuthUser):
    phone_number = models.CharField(max_length=15, blank=True)
    date_of_birth = models.DateField(null=True, blank=True)

    # Don't forget to update AUTH_USER_MODEL in settings to point to your custom model

Custom Serializers

You can override the default serializers by specifying them in your settings:

QUICK_AUTH = {
    # Other settings...
    'USER_SERIALIZER': 'myapp.serializers.MyCustomUserSerializer',
    'LOGIN_SERIALIZER': 'myapp.serializers.MyCustomLoginSerializer',
    'SIGNUP_SERIALIZER': 'myapp.serializers.MyCustomSignupSerializer',
}

Testing

To run the tests for this package:

pip install -e .
pip install pytest pytest-django
pytest

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -am 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tc-django-quick-auth-0.1.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tc_django_quick_auth-0.1.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file tc-django-quick-auth-0.1.2.tar.gz.

File metadata

  • Download URL: tc-django-quick-auth-0.1.2.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for tc-django-quick-auth-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0af8c8d9e6faaf61824d1408099696991dddc9549238fc6a1acc9fbf457ad10f
MD5 a91d6b12900dd19a1ac52b55b7d6cf83
BLAKE2b-256 9b2c53de58f54f99862623f646d52f393af5b94469d227b69351dc942445b7a3

See more details on using hashes here.

File details

Details for the file tc_django_quick_auth-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for tc_django_quick_auth-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ce285a2a35f8e6a5a95b0a354e4a2e3a5efe44ca26cdf005cda54ee64db9c43d
MD5 d0c03e533b499a57e9a20f7d32bf5edb
BLAKE2b-256 7c6fbf5a5eb09537aca36acab56d002e5f7598e0f95499a80c49d326bb4a249b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page