Skip to content

A simple Django REST authentication system with Djoser token support.

Notifications You must be signed in to change notification settings

1806exe/djoser-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Users App with Djoser for Token Authentication

Overview

This Django application demonstrates how to set up token authentication using Djoser and a custom user model named "User" in the "users" app.

Prerequisites

  • Python 3.x
  • Django
  • Djoser

Setup

  1. Clone the Repository:

    git clone https://github.com/yourusername/django-users-djoser-token-auth.git
  2. Install Dependencies:

    pip install -r requirements.txt
  3. Run Migrations:

    python manage.py migrate
  4. Create a Superuser:

    python manage.py createsuperuser
  5. Run the Development Server:

    python manage.py runserver

    The application will be accessible at http://localhost:8000/

Djoser Configuration

The Djoser configuration is set up in the settings.py file within the "users" app. Ensure that the following configurations are correctly set:

INSTALLED_APPS = [
    # ...
    'djoser',
    'users',
    # ...
]

# ...

DJOSER = {
    'SERIALIZERS': {
        'user_create': 'users.serializers.CustomUserCreateSerializer',
        'user': 'users.serializers.CustomUserSerializer',
        'token_create': 'djoser.serializers.TokenCreateSerializer',
    },
    # Other Djoser settings...
}

Usage

  1. User Registration:

    Endpoint: /auth/users/

    Use a POST request with the following payload:

    {
        "email": "[email protected]",
        "password": "yourpassword",
        "first_name": "John",
        "last_name": "Doe",
        "bio": "A brief bio",
        "date_of_birth": "1990-01-01"
    }
  2. User Login:

    Endpoint: /auth/token/login/

    Use a POST request with the following payload:

    {
        "email": "[email protected]",
        "password": "yourpassword"
    }

    The response will include an access token.

  3. Access Protected Endpoints:

    Include the access token in the Authorization header to access protected endpoints.

    curl -H "Authorization: Token <your-access-token>" http://localhost:8000/protected-endpoint/
  4. Superuser Access:

    Superuser credentials can be used to access all endpoints and perform administrative actions.

Custom User Model

The custom user model is defined in users/models.py. Ensure that the AUTH_USER_MODEL setting in settings.py is correctly set to 'users.User'.

# settings.py
AUTH_USER_MODEL = 'users.User'

Contributing

Feel free to contribute to this project by submitting bug reports, feature requests, or pull requests.

License

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


Replace "yourusername" with your actual GitHub username in the clone URL, and customize the file paths, payload examples, and other details according to your specific application.

About

A simple Django REST authentication system with Djoser token support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages