From 7e98943c9d15b2f81f83fc6bfc75e9b3a57eb31c Mon Sep 17 00:00:00 2001 From: decorator-factory <42166884+decorator-factory@users.noreply.github.com> Date: Tue, 15 Dec 2020 08:28:22 +0300 Subject: minor refactorings --- backend/authentication/backend.py | 7 +++---- backend/authentication/user.py | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'backend/authentication') diff --git a/backend/authentication/backend.py b/backend/authentication/backend.py index e4699bd..f1d2ece 100644 --- a/backend/authentication/backend.py +++ b/backend/authentication/backend.py @@ -1,6 +1,5 @@ import jwt import typing as t -from abc import ABC from starlette import authentication from starlette.requests import Request @@ -10,7 +9,7 @@ from backend import constants from .user import User -class JWTAuthenticationBackend(authentication.AuthenticationBackend, ABC): +class JWTAuthenticationBackend(authentication.AuthenticationBackend): """Custom Starlette authentication backend for JWT.""" @staticmethod @@ -35,7 +34,7 @@ class JWTAuthenticationBackend(authentication.AuthenticationBackend, ABC): ) -> t.Optional[tuple[authentication.AuthCredentials, authentication.BaseUser]]: """Handles JWT authentication process.""" if "Authorization" not in request.headers: - return + return None auth = request.headers["Authorization"] token = self.get_token_from_header(auth) @@ -47,7 +46,7 @@ class JWTAuthenticationBackend(authentication.AuthenticationBackend, ABC): scopes = ["authenticated"] - if payload.get("admin", False) is True: + if payload.get("admin") is True: scopes.append("admin") return authentication.AuthCredentials(scopes), User(token, payload) diff --git a/backend/authentication/user.py b/backend/authentication/user.py index 3bed0a1..722c348 100644 --- a/backend/authentication/user.py +++ b/backend/authentication/user.py @@ -1,10 +1,9 @@ import typing as t -from abc import ABC from starlette.authentication import BaseUser -class User(BaseUser, ABC): +class User(BaseUser): """Starlette BaseUser implementation for JWT authentication.""" def __init__(self, token: str, payload: dict[str, t.Any]) -> None: -- cgit v1.2.3