def dispatch(self, request, *args, **kwargs): assert rest_framework is not None, "django rest framework is not installed." if request.method.lower() != 'options': user_auth_tuple = None for auth in self.authentications: try: user_auth_tuple = auth.authenticate(RequestWrapper(request)) except APIException as e: return HttpResponse(e.detail, status=e.status_code) else: if user_auth_tuple is None: continue # try next authenticator else: break # we got auth, so stop trying if user_auth_tuple is not None: user, auth = user_auth_tuple else: resp = HttpResponseUnAuthorized("Not Authorised") resp['WWW-Authenticate'] = self.authentications[0].authenticate_header(request) return resp request.user = user request.auth = auth return super(RestAuthViewMixIn, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs): if request.method.lower() != 'options': auth_result = self.authentication.is_authenticated(request) if isinstance(auth_result, HttpResponse): return auth_result if auth_result is not True: return HttpResponseUnAuthorized() return super(TastypieAuthViewMixIn, self).dispatch(request, *args, **kwargs)