Skip to content

melvinthomasdev/django-REST-TokenAuth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

django-REST-TokenAuth

A django app that can be added to your projects to implement TokenAuthentication.

Features

  • Custom User model with email as the username field.
  • Extendable UserProfile model to add additional fields to the user.
  • TokenAuthentication for API endpoints.

Before you start

  • please ensure that you do not have any migrations applied to the database. Otherwise, it may cause issues.
  • It is advised you add this app right after creating the project, before running any migrations.

How to use

  1. Clone this repository and copy the accounts directory to your project root directory.
  2. Install requirements using pip install -r accounts/requirements.txt
  3. Add the following to your INSTALLED_APPS in settings.py
INSTALLED_APPS = [
    ...
    'rest_framework',
    'rest_framework.authtoken',
    'import_export',

    'accounts',
    ...
]
  1. Set "AUTH_USER_MODEL" in settings.py to "accounts.User"
AUTH_USER_MODEL = 'accounts.User'
  1. Add the following at the end of settings file
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',
    ]
}
  1. In urls.py add the following
url = [
    ...
    path('account/', include('accounts.urls')),
    ...
]
  1. Run migrations using python manage.py migrate
  2. Now you can register a superuser using python manage.py createsuperuser and start using the API with TokenAuthentication.
  3. Refer to the API Documentation Available here for more details.

Contributing

  • Fork the repository
  • Create a new branch
  • Make your changes
  • Create a pull request

Please Star the repo and share it with your friends if you find it useful. Follow me for more such projects.

About

A django app that can be added to your projects to implement TokenAuthentication.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages