Skip to content

Commit c843809

Browse files
authored
Switch access token generating scheme to secrets.token_urlsafe(16) (#1452)
1 parent 1230d79 commit c843809

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

pydatalab/src/pydatalab/permissions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ def check_access_token(refcode: str, token: str | None = None) -> bool:
135135
{"token": token_hash, "refcode": refcode, "active": True, "type": "access_token"}
136136
)
137137

138+
if access_token_doc and access_token_doc["expires_at"] is not None:
139+
raise NotImplementedError("Token expiration is not yet implemented")
140+
138141
return bool(access_token_doc)
139142

140143
except Exception:

pydatalab/src/pydatalab/routes/v0_1/items.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22
import json
33
import re
4-
import uuid
4+
import secrets
55
from hashlib import sha512
66

77
from bson import ObjectId
@@ -818,13 +818,14 @@ def issue_physical_token(refcode: str):
818818
}
819819
), 404
820820

821-
token = str(uuid.uuid1())
821+
token = secrets.token_urlsafe(16)
822822
access_document = {
823823
"token": sha512(token.encode("utf-8")).hexdigest(),
824824
"refcode": refcode,
825825
"user": ObjectId(current_user.id),
826826
"active": True,
827827
"created_at": datetime.datetime.now(tz=datetime.timezone.utc),
828+
"expires_at": None,
828829
"version": 1,
829830
"type": "access_token",
830831
}

0 commit comments

Comments
 (0)