From e995d8647c532611e45b8e508ef4b2a303e897b9 Mon Sep 17 00:00:00 2001 From: Jack Amadeo Date: Fri, 8 Nov 2024 11:53:32 -0500 Subject: [PATCH] Prefer the gsheet token --- server/kernels/kernel_handlers.py | 16 ++++++++-------- server/users.py | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/server/kernels/kernel_handlers.py b/server/kernels/kernel_handlers.py index 64deab7..e6db109 100644 --- a/server/kernels/kernel_handlers.py +++ b/server/kernels/kernel_handlers.py @@ -116,7 +116,14 @@ async def init_connection( with self.make_session() as session: user: User | NonUser self.user_profile_image = "" - if auth_token: + if gsheet_auth_token: + assert gsheet_auth_token + user = NonUser.GSHEET + claims = decode_gsheet_extension_token(gsheet_auth_token) + self.user_id = None + self.user_name = f"anon-{claims.sheet_id}" + self.user_email = f"{self.user_name}@example.com" + else: user = await authenticate_request(self, session, token=auth_token) self.user_email = user.email self.user_name = user.name @@ -124,13 +131,6 @@ async def init_connection( self.allow_other_gsheets = bool( self.user_email ) and self.user_email.endswith("@neptyne.com") - else: - assert gsheet_auth_token - user = NonUser.GSHEET - claims = decode_gsheet_extension_token(gsheet_auth_token) - self.user_id = None - self.user_name = f"anon-{claims.sheet_id}" - self.user_email = f"{self.user_name}@example.com" tyne_proxy = await self.tyne_contents_manager.get( self.tyne_id, session, user, gsheet_auth_token diff --git a/server/users.py b/server/users.py index 06e5667..780d59c 100644 --- a/server/users.py +++ b/server/users.py @@ -19,9 +19,10 @@ def token_from_headers(request_handler: web.RequestHandler) -> str | None: + header = request_handler.request.headers.get("X-Neptyne-GSheet-Auth-Token") + if header: + return header header = request_handler.request.headers.get("Authorization") - if not header: - return request_handler.request.headers.get("X-Neptyne-GSheet-Auth-Token") parts = header.split(" ") if len(parts) != 2 or parts[0].lower() != "bearer":