aboutsummaryrefslogtreecommitdiffstats
path: root/backend/authentication
diff options
context:
space:
mode:
authorGravatar decorator-factory <[email protected]>2020-12-15 08:28:22 +0300
committerGravatar decorator-factory <[email protected]>2020-12-15 08:28:22 +0300
commit7e98943c9d15b2f81f83fc6bfc75e9b3a57eb31c (patch)
treec7d7f209dd28abe1c2182e3fb55ea275fc628cb9 /backend/authentication
parentfix various type annotation issues (diff)
minor refactorings
Diffstat (limited to 'backend/authentication')
-rw-r--r--backend/authentication/backend.py7
-rw-r--r--backend/authentication/user.py3
2 files changed, 4 insertions, 6 deletions
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: