-
-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ds_author cookie can now expire, closes #829
- Loading branch information
Showing
9 changed files
with
99 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
from datasette import hookimpl | ||
from itsdangerous import BadSignature | ||
import baseconv | ||
import time | ||
|
||
|
||
@hookimpl | ||
def actor_from_request(datasette, request): | ||
if "ds_actor" not in request.cookies: | ||
return None | ||
try: | ||
return datasette.unsign(request.cookies["ds_actor"], "actor") | ||
decoded = datasette.unsign(request.cookies["ds_actor"], "actor") | ||
# If it has "e" and "a" keys process the "e" expiry | ||
if not isinstance(decoded, dict) or "a" not in decoded: | ||
return None | ||
expires_at = decoded.get("e") | ||
if expires_at: | ||
timestamp = int(baseconv.base62.decode(expires_at)) | ||
if time.time() > timestamp: | ||
return None | ||
return decoded["a"] | ||
except BadSignature: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters