예제 #1
0
    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)
예제 #2
0
파일: tasty.py 프로젝트: pellaeon/djangodav
    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)