Coverage for datasette/actor_auth_cookie.py : 84%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from datasette import hookimpl
2from itsdangerous import BadSignature
3import baseconv
4import time
7@hookimpl
8def actor_from_request(datasette, request):
9 if "ds_actor" not in request.cookies:
10 return None
11 try:
12 decoded = datasette.unsign(request.cookies["ds_actor"], "actor")
13 # If it has "e" and "a" keys process the "e" expiry
14 if not isinstance(decoded, dict) or "a" not in decoded:
15 return None
16 expires_at = decoded.get("e")
17 if expires_at:
18 timestamp = int(baseconv.base62.decode(expires_at))
19 if time.time() > timestamp:
20 return None
21 return decoded["a"]
22 except BadSignature:
23 return None