def initialize_request(request): """ Returns the initial request object. """ # todo: get authenticators from setting file return Request(request, authenticators=[ jwt_auth.JWTAuthentication(), authentication.SessionAuthentication(), authentication.TokenAuthentication() ])
def wrapper(request): result = get_response(request) try: user, token = authentication.TokenAuthentication().authenticate( request) print(f'-- drf_user_info --'.ljust(30), f' : ID /User / Token] ---> {user.id} / {user} / {token}') except: print(f'-- drf_user_info --'.ljust(30), f'AUTH FAILED!') return result
def authenticate(self, request): if CHECK_IF_REST_API_DISABLED and not ProjectSettings.getIsRESTAPIEnabled(): raise exceptions.AuthenticationFailed('REST API of this site is disabled.') # # I user TokenAuthentication here to illustrate an implementation # of custom authentication in REST framework _auth = authentication.TokenAuthentication() result = _auth.authenticate(request) if not result: raise exceptions.AuthenticationFailed('Authentication failed.') userAccount, token = result if not userAccount.has_account_been_verified: raise exceptions.AuthenticationFailed('User has not been verified yet.') # Do further authenticate here return result
from rest_framework import permissions from rest_framework import response from rest_framework import status from sendfile import sendfile import dashboard.models import docserver from docserver import forms from docserver import jobs from docserver import log from docserver import models from docserver import serializers from docserver import util from dunya.celery import app auther = authentication.TokenAuthentication() def index(request): return HttpResponse("Hello docserver") class CollectionList(generics.ListAPIView): queryset = models.Collection.objects.all() serializer_class = serializers.CollectionListSerializer class CollectionDetail(generics.RetrieveAPIView): lookup_field = 'slug' queryset = models.Collection.objects.all() serializer_class = serializers.CollectionDetailSerializer