Skip to content

Commit

Permalink
Extract raising on unsupported token.
Browse files Browse the repository at this point in the history
  • Loading branch information
thedrow committed Dec 17, 2018
1 parent cfd6af0 commit 79c667e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
9 changes: 8 additions & 1 deletion oauthlib/oauth2/rfc6749/endpoints/base.py
Expand Up @@ -13,7 +13,7 @@

from ..errors import (FatalClientError, OAuth2Error, ServerError,
TemporarilyUnavailableError, InvalidRequestError,
InvalidClientError)
InvalidClientError, UnsupportedTokenTypeError)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -55,6 +55,13 @@ def _raise_on_invalid_client(self, request):
log.debug('Client authentication failed, %r.', request)
raise InvalidClientError(request=request)

def _raise_on_unspported_token(self, request):
"""Raise on unsupported tokens."""
if (request.token_type_hint and
request.token_type_hint in self.valid_token_types and
request.token_type_hint not in self.supported_token_types):
raise UnsupportedTokenTypeError(request=request)


def catch_errors_and_unavailability(f):
@functools.wraps(f)
Expand Down
6 changes: 1 addition & 5 deletions oauthlib/oauth2/rfc6749/endpoints/introspect.py
Expand Up @@ -118,8 +118,4 @@ def validate_introspect_request(self, request):
"""
self._raise_on_missing_token(request)
self._raise_on_invalid_client(request)

if (request.token_type_hint and
request.token_type_hint in self.valid_token_types and
request.token_type_hint not in self.supported_token_types):
raise UnsupportedTokenTypeError(request=request)
self._raise_on_unspported_token(request)
6 changes: 1 addition & 5 deletions oauthlib/oauth2/rfc6749/endpoints/revocation.py
Expand Up @@ -117,8 +117,4 @@ def validate_revocation_request(self, request):
"""
self._raise_on_missing_token(request)
self._raise_on_invalid_client(request)

if (request.token_type_hint and
request.token_type_hint in self.valid_token_types and
request.token_type_hint not in self.supported_token_types):
raise UnsupportedTokenTypeError(request=request)
self._raise_on_unspported_token(request)

0 comments on commit 79c667e

Please sign in to comment.