Skip to content

Commit

Permalink
Prefer the gsheet token
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadeo committed Nov 8, 2024
1 parent 721c61b commit e995d86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 8 additions & 8 deletions server/kernels/kernel_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,21 @@ 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
self.user_id = user.id
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
Expand Down
5 changes: 3 additions & 2 deletions server/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit e995d86

Please sign in to comment.