djoser is a library that supports basic user authentication and registration on the Django REST Framework. It can also be used for custom models, and is designed for an architecture that fits better with a Single Page Application (SPA) rather than reusing Django's code.
This time I will write about the implementation of the simplest authentication function of djoser. Please note that this authentication should not be actually used for security reasons, and there are stronger security settings such as the JWT authentication below. I will introduce it as a simple authentication to the last.
JWT authentication settings are explained in here.
All of the following can be used as endpoints after installation.
/users/ /users/me/ /users/confirm/ /users/resend_activation/ /users/set_password/ /users/reset_password/ /users/reset_password_confirm/ /users/set_username/ /users/reset_username/ /users/reset_username_confirm/ /token/login/ (Token Based Authentication) /token/logout/ (Token Based Authentication) /jwt/create/ (JSON Web Token Authentication) /jwt/refresh/ (JSON Web Token Authentication) /jwt/verify/ (JSON Web Token Authentication) Getting started
First of all, from the installation.
$ pip install -U djoser
First, make a project,
$ django-admin startproject simple_djoser_authentication
Go within the project.
$ cd simple_djoser_authentication
We'll set up Django.
setings.py
.........
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework', # add
'djoser' # add
]
urls.py
from django.contrib import admin
from django.urls import path,include #add
urlpatterns = [
path('admin/', admin.site.urls),
path('api/auth/',include('djoser.urls')), #add
]
Only this.
After this, migrate, create an Admin user and launch it locally.
$ python manage.py migrations
$ python manage.py createsuperuser
Username: Admin
Email address: [email protected]
Password:***********
$ python manage.py runserver
And http://localhost:8000/api/auth/ To access.
Then
The above screen will be displayed.
And then http://localhost:8000/api/auth/users/ When you access
The above list of user information is displayed.
This completes the introduction of the basic functions around authentication.
Recommended Posts