From 7cd5929df2cd0ca91efb747220cdbbea48fad189 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 13 Oct 2023 14:47:31 +0300 Subject: [PATCH] token-type-tolerance --- auth/authenticate.py | 3 +-- resolvers/auth.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/auth/authenticate.py b/auth/authenticate.py index 18bf11c3..255b4a5c 100644 --- a/auth/authenticate.py +++ b/auth/authenticate.py @@ -29,8 +29,7 @@ class JWTAuthenticate(AuthenticationBackend): user_id=None, username="" ) - if token.startswith("Bearer"): - token = token[len("Bearer "):] + token = token.split(" ")[-1] if len(token.split(".")) > 1: payload = await SessionToken.verify(token) diff --git a/resolvers/auth.py b/resolvers/auth.py index 6e2c894b..2cb7058b 100644 --- a/resolvers/auth.py +++ b/resolvers/auth.py @@ -33,8 +33,7 @@ async def get_current_user(_, info): auth: AuthCredentials = info.context["request"].auth token = info.context["request"].headers.get(SESSION_TOKEN_HEADER) - if token.startswith("Bearer"): - token = token[len("Bearer "):] + token = token.split(" ")[-1] with local_session() as session: user = session.query(User).where(User.id == auth.user_id).one()