Ejemplo n.º 1
0
 def authenticate_credentials(self, request, access_token):
     """
     Authenticate the request, given the access token.
     Overrides base class implementation to discard failure if user is inactive.
     """
     token_query = oauth2_provider.oauth2.models.AccessToken.objects.select_related("user")
     token = token_query.filter(token=access_token).first()
     if not token:
         raise AuthenticationFailed(
             {
                 u"error_code": OAUTH2_TOKEN_ERROR_NONEXISTENT,
                 u"developer_message": u"The provided access token does not match any valid tokens.",
             }
         )
     # provider_now switches to timezone aware datetime when
     # the oauth2_provider version supports it.
     elif token.expires < provider_now():
         raise AuthenticationFailed(
             {
                 u"error_code": OAUTH2_TOKEN_ERROR_EXPIRED,
                 u"developer_message": u"The provided access token has expired and is no longer valid.",
             }
         )
     else:
         return token.user, token
Ejemplo n.º 2
0
 def authenticate_credentials(self, request, access_token):
     """
     Authenticate the request, given the access token.
     Overrides base class implementation to discard failure if user is inactive.
     """
     token_query = oauth2_provider.oauth2.models.AccessToken.objects.select_related(
         'user')
     token = token_query.filter(token=access_token).first()
     if not token:
         raise AuthenticationFailed({
             u'error_code':
             OAUTH2_TOKEN_ERROR_NONEXISTENT,
             u'developer_message':
             u'The provided access token does not match any valid tokens.'
         })
     # provider_now switches to timezone aware datetime when
     # the oauth2_provider version supports it.
     elif token.expires < provider_now():
         raise AuthenticationFailed({
             u'error_code':
             OAUTH2_TOKEN_ERROR_EXPIRED,
             u'developer_message':
             u'The provided access token has expired and is no longer valid.',
         })
     else:
         return token.user, token
Ejemplo n.º 3
0
    def authenticate_credentials(self, request, access_token):
        """
        Authenticate the request, given the access token.
        Override base class implementation to discard failure if user is inactive.
        """
        try:
            token = oauth2_provider.oauth2.models.AccessToken.objects.select_related('user')
            # provider_now switches to timezone aware datetime when
            # the oauth2_provider version supports to it.
            token = token.get(token=access_token, expires__gt=provider_now())
        except oauth2_provider.oauth2.models.AccessToken.DoesNotExist:
            raise AuthenticationFailed('Invalid token')

        return token.user, token
Ejemplo n.º 4
0
    def authenticate_credentials(self, request, access_token):
        """
        Authenticate the request, given the access token.
        Override base class implementation to discard failure if user is inactive.
        """
        try:
            token = oauth2_provider.oauth2.models.AccessToken.objects.select_related(
                'user')
            # provider_now switches to timezone aware datetime when
            # the oauth2_provider version supports to it.
            token = token.get(token=access_token, expires__gt=provider_now())
        except oauth2_provider.oauth2.models.AccessToken.DoesNotExist:
            raise AuthenticationFailed('Invalid token')

        return token.user, token