A django app that can be added to your projects to implement TokenAuthentication.
- Custom User model with email as the username field.
- Extendable
UserProfile
model to add additional fields to the user. - TokenAuthentication for API endpoints.
- 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.
- Clone this repository and copy the accounts directory to your project root directory.
- Install requirements using
pip install -r accounts/requirements.txt
- Add the following to your INSTALLED_APPS in settings.py
INSTALLED_APPS = [
...
'rest_framework',
'rest_framework.authtoken',
'import_export',
'accounts',
...
]
- Set "AUTH_USER_MODEL" in settings.py to "accounts.User"
AUTH_USER_MODEL = 'accounts.User'
- 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',
]
}
- In urls.py add the following
url = [
...
path('account/', include('accounts.urls')),
...
]
- Run migrations using
python manage.py migrate
- Now you can register a superuser using
python manage.py createsuperuser
and start using the API with TokenAuthentication. - Refer to the API Documentation Available here for more details.
- Fork the repository
- Create a new branch
- Make your changes
- Create a pull request