From 79c667eedae4a4d447e8229e37eb844e3af05374 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 17 Dec 2018 15:19:51 +0200 Subject: Extract raising on unsupported token. --- oauthlib/oauth2/rfc6749/endpoints/base.py | 9 ++++++++- oauthlib/oauth2/rfc6749/endpoints/introspect.py | 6 +----- oauthlib/oauth2/rfc6749/endpoints/revocation.py | 6 +----- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'oauthlib/oauth2/rfc6749') diff --git a/oauthlib/oauth2/rfc6749/endpoints/base.py b/oauthlib/oauth2/rfc6749/endpoints/base.py index 638311d..3fd45c3 100644 --- a/oauthlib/oauth2/rfc6749/endpoints/base.py +++ b/oauthlib/oauth2/rfc6749/endpoints/base.py @@ -13,7 +13,7 @@ import logging from ..errors import (FatalClientError, OAuth2Error, ServerError, TemporarilyUnavailableError, InvalidRequestError, - InvalidClientError) + InvalidClientError, UnsupportedTokenTypeError) log = logging.getLogger(__name__) @@ -55,6 +55,13 @@ class BaseEndpoint(object): 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) diff --git a/oauthlib/oauth2/rfc6749/endpoints/introspect.py b/oauthlib/oauth2/rfc6749/endpoints/introspect.py index 5f24ff3..25dae1f 100644 --- a/oauthlib/oauth2/rfc6749/endpoints/introspect.py +++ b/oauthlib/oauth2/rfc6749/endpoints/introspect.py @@ -118,8 +118,4 @@ class IntrospectEndpoint(BaseEndpoint): """ 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) diff --git a/oauthlib/oauth2/rfc6749/endpoints/revocation.py b/oauthlib/oauth2/rfc6749/endpoints/revocation.py index 8ec9512..f9a5648 100644 --- a/oauthlib/oauth2/rfc6749/endpoints/revocation.py +++ b/oauthlib/oauth2/rfc6749/endpoints/revocation.py @@ -117,8 +117,4 @@ class RevocationEndpoint(BaseEndpoint): """ 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) -- cgit v1.2.1