Skip to content

Commit

Permalink
Merge pull request #2 from neptyneco/check-neptyne-token
Browse files Browse the repository at this point in the history
Check the other thing
  • Loading branch information
jamadeo authored Nov 8, 2024
2 parents 3ddf8d9 + 91c2f96 commit 9eb227f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 210 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ The easiest way to get started is to use the docker image. This will give you a

```shell

docker-compose up -d
docker compose up -d
docker logs neptyne-spreadsheet-neptyne-1

```

Only need to build it once. After that, you can just run `docker-compose up`.
The second statement will print out the shared secret you need to connect to the Neptyne server.
Open that url and you are in business.

```shell

### Method 2: pip install

Expand Down
196 changes: 0 additions & 196 deletions frontend/src/neptyne-container/NeptyneModals.test.tsx

This file was deleted.

1 change: 1 addition & 0 deletions neptyne_kernel/neptyne_api/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def dataset(name_or_url: str) -> GeoDataFrame:
path = geopandas.datasets.get_path(name_or_url)
else:
import geoplot

try:
path = geoplot.datasets.get_path(name_or_url)
except ValueError:
Expand Down
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
14 changes: 10 additions & 4 deletions server/users.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Any, Literal

from jwt import PyJWTError
from sqlalchemy import func
from sqlalchemy.orm import Session
from tornado import web
from tornado_sqlalchemy import SessionMixin

from server.gsheet_auth import decode_gsheet_extension_token
from server.models import (
EmailShare,
FirebaseUser,
Expand All @@ -17,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 None

parts = header.split(" ")
if len(parts) != 2 or parts[0].lower() != "bearer":
Expand Down Expand Up @@ -55,8 +58,11 @@ async def _authenticate_request(
)
if not token:
raise web.HTTPError(401, "Missing token")
if not token == shared_secret: # TODO: also check for a signed token
raise web.HTTPError(401, "Invalid token")
if not token == shared_secret:
try:
decode_gsheet_extension_token(token)
except PyJWTError:
raise web.HTTPError(401, "Invalid token")
return await load_user(
session,
"<single-user-firebase-uid>",
Expand Down

0 comments on commit 9eb227f

Please sign in to comment.