From fe2b581d67d7f2b41c576201615f14118266833b Mon Sep 17 00:00:00 2001 From: "dorin.clisu" Date: Sun, 18 Apr 2021 15:08:34 +0300 Subject: [PATCH] rename Auth0...Error to Auth0...Exception --- setup.py | 2 +- src/fastapi_auth0/__init__.py | 2 +- src/fastapi_auth0/auth.py | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 447aa77..4c1f210 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name='fastapi-auth0', - version='0.1.7', + version='0.2.0', description='Easy auth0.com integration for FastAPI', long_description=readme, long_description_content_type='text/markdown', diff --git a/src/fastapi_auth0/__init__.py b/src/fastapi_auth0/__init__.py index 20ff699..9a4b61b 100644 --- a/src/fastapi_auth0/__init__.py +++ b/src/fastapi_auth0/__init__.py @@ -1,2 +1,2 @@ -from .auth import Auth0, Auth0User, Auth0UnauthenticatedError, Auth0UnauthorizedError +from .auth import Auth0, Auth0User, Auth0UnauthenticatedException, Auth0UnauthorizedException from .auth import security_responses, auth0_rule_namespace diff --git a/src/fastapi_auth0/auth.py b/src/fastapi_auth0/auth.py index afecea3..a38cb7e 100644 --- a/src/fastapi_auth0/auth.py +++ b/src/fastapi_auth0/auth.py @@ -17,11 +17,11 @@ auth0_rule_namespace: str = os.getenv('AUTH0_RULE_NAMESPACE', 'https://github.com/dorinclisu/fastapi-auth0') -class Auth0UnauthenticatedError(HTTPException): +class Auth0UnauthenticatedException(HTTPException): def __init__(self, **kwargs): super().__init__(401, **kwargs) -class Auth0UnauthorizedError(HTTPException): +class Auth0UnauthorizedException(HTTPException): def __init__(self, **kwargs): super().__init__(403, **kwargs) @@ -132,26 +132,26 @@ async def get_user(self, except jwt.ExpiredSignatureError: if self.auto_error: - raise Auth0UnauthenticatedError(detail='Expired token') + raise Auth0UnauthenticatedException(detail='Expired token') else: return None except jwt.JWTClaimsError: if self.auto_error: - raise Auth0UnauthenticatedError(detail='Invalid token claims (please check issuer and audience)') + raise Auth0UnauthenticatedException(detail='Invalid token claims (please check issuer and audience)') else: return None except jwt.JWTError: if self.auto_error: - raise Auth0UnauthenticatedError(detail='Malformed token') + raise Auth0UnauthenticatedException(detail='Malformed token') else: return None except Exception as e: logging.error(f'Handled exception decoding token: "{e}"') if self.auto_error: - raise Auth0UnauthenticatedError(detail='Error decoding token') + raise Auth0UnauthenticatedException(detail='Error decoding token') else: return None @@ -163,24 +163,24 @@ async def get_user(self, for scope in security_scopes.scopes: if scope not in token_scopes: - raise Auth0UnauthorizedError(detail=f'Missing "{scope}" scope', + raise Auth0UnauthorizedException(detail=f'Missing "{scope}" scope', headers={'WWW-Authenticate': f'Bearer scope="{security_scopes.scope_str}"'}) else: # This is an unlikely case but handle it just to be safe (perhaps auth0 will change the scope format) - raise Auth0UnauthorizedError(detail='Token "scope" field must be a string') + raise Auth0UnauthorizedException(detail='Token "scope" field must be a string') try: user = self.auth0_user_model(**payload) if self.email_auto_error and not user.email: - raise Auth0UnauthorizedError(detail=f'Missing email claim (check auth0 rule "Add email to access token")') + raise Auth0UnauthorizedException(detail=f'Missing email claim (check auth0 rule "Add email to access token")') return user except ValidationError as e: logging.error(f'Handled exception parsing Auth0User: "{e}"') if self.auto_error: - raise Auth0UnauthorizedError(detail='Error parsing Auth0User') + raise Auth0UnauthorizedException(detail='Error parsing Auth0User') else: return None