Up to the last time, we have already authenticated and issued an authentication token!
All you have to do now is return the authentication token to the client!
First, set up a module in Django to use the session
settings.py
INSTALLED_APPS = [
'django.contrib.sessions',
]
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
]
All you have to do is set an authentication token for your session!
authentivateservcice.py
#Get authentication token
authenticateToken = self._authService.authenticate(user=userCresidented)
#JSON authentication token
jsonedToken = serializers.serialize("json", authenticateToken)
#Save token in session
request.session['AuthenticateToken'] = jsonedToken
The token call looks like this
sample_view_tenplate.py
def post(self, request):
#Register user
token = request.session['AuthenticateToken']
#Compare and authorize the hash of token variables
Only JSON format strings can be registered in the session! So you're serializing the token and turning it into a string!
reference Django Official Document How to Use Session Session serialization term https://docs.djangoproject.com/ja/3.1/topics/http/sessions/
Django Official Document Serialization of Objects https://djangoproject.jp/doc/ja/1.0/topics/serialization.html
Recommended Posts