refactored logout endpoint
This commit is contained in:
parent
de0a1d6358
commit
6d95349a52
|
|
@ -1,20 +1,18 @@
|
|||
"""Common serializer for application authorization"""
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth import password_validation as password_validators
|
||||
from django.db.models import Q
|
||||
from rest_framework import serializers
|
||||
from rest_framework import validators as rest_validators
|
||||
from django.contrib.auth import authenticate
|
||||
from django.db.models import Q
|
||||
from django.conf import settings
|
||||
# JWT
|
||||
from rest_framework_simplejwt import tokens
|
||||
|
||||
from account import models as account_models
|
||||
from authorization.models import Application, BlacklistedAccessToken
|
||||
from utils import exceptions as utils_exceptions
|
||||
from utils import methods as utils_methods
|
||||
|
||||
# JWT
|
||||
from rest_framework_simplejwt import tokens
|
||||
|
||||
|
||||
JWT_SETTINGS = settings.SIMPLE_JWT
|
||||
|
||||
|
||||
|
|
@ -202,8 +200,8 @@ class LogoutSerializer(serializers.ModelSerializer):
|
|||
def validate(self, attrs):
|
||||
"""Override validated data"""
|
||||
request = self.context.get('request')
|
||||
token = request._request.headers.get('Authorization') \
|
||||
.split(' ')[::-1][0]
|
||||
token = request.headers.get('Authorization') \
|
||||
.split(' ')[::-1][0]
|
||||
access_token = tokens.AccessToken(token)
|
||||
# Prepare validated data
|
||||
attrs['user'] = request.user
|
||||
|
|
|
|||
|
|
@ -23,27 +23,18 @@ urlpatterns_social_django = [
|
|||
urlpatterns_oauth2 = [
|
||||
path('oauth2/signup/facebook/', views.OAuth2SignUpView.as_view(),
|
||||
name='oauth2-signup-facebook'),
|
||||
# for admin sign in page
|
||||
path('oauth2/token/', drf_social_oauth2_views .TokenView.as_view(),
|
||||
name="token"),
|
||||
# for sign up via facebook
|
||||
path('oauth2/token/', drf_social_oauth2_views .TokenView.as_view(), name="token"),
|
||||
]
|
||||
|
||||
urlpatterns_jwt = [
|
||||
path('signup/', views.SignUpView.as_view(),
|
||||
name='signup'),
|
||||
# sign in
|
||||
path('login/', views.LoginByUsernameOrEmailView.as_view(),
|
||||
name='login'),
|
||||
# refresh token
|
||||
path('refresh-token/', views.RefreshTokenView.as_view(),
|
||||
name="refresh-token"),
|
||||
# logout
|
||||
path('logout/', views.LogoutView.as_view(),
|
||||
name="logout"),
|
||||
path('signup/', views.SignUpView.as_view(), name='signup'),
|
||||
path('login/', views.LoginByUsernameOrEmailView.as_view(), name='login'),
|
||||
path('refresh-token/', views.RefreshTokenView.as_view(), name="refresh-token"),
|
||||
path('logout/', views.LogoutView.as_view(), name="logout"),
|
||||
]
|
||||
|
||||
|
||||
urlpatterns = urlpatterns_jwt + \
|
||||
urlpatterns_oauth2 + \
|
||||
urlpatterns_social_django # for social oauth2
|
||||
|
||||
|
|
|
|||
|
|
@ -210,9 +210,9 @@ class LogoutView(JWTGenericViewMixin):
|
|||
"""Logout user"""
|
||||
serializer_class = serializers.LogoutSerializer
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""Override create method"""
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save()
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user