Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Document the ds_actor signed cookie #826

Closed
simonw opened this issue Jun 9, 2020 · 3 comments
Closed

Document the ds_actor signed cookie #826

simonw opened this issue Jun 9, 2020 · 3 comments

Comments

@simonw
Copy link
Owner

simonw commented Jun 9, 2020

Most authentication plugins (https://github.com/simonw/datasette-auth-github for example) are likely to work by setting the ds_actor signed cookie, which is already magically decoded and supported by default Datasette here:

from datasette import hookimpl
from itsdangerous import BadSignature
from http.cookies import SimpleCookie
@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")
except BadSignature:
return None

I should document this.

@simonw
Copy link
Owner Author

simonw commented Jun 9, 2020

I should probably add a utility function for setting that cookie - right now the only code that does that is here:

if secrets.compare_digest(token, self.ds._root_token):
self.ds._root_token = None
cookie = SimpleCookie()
cookie["ds_actor"] = self.ds.sign({"id": "root"}, "actor")
cookie["ds_actor"]["path"] = "/"
response = Response(
body="",
status=302,
headers={
"Location": "/",
"set-cookie": cookie.output(header="").lstrip(),
},
)
return response

@simonw
Copy link
Owner Author

simonw commented Jun 9, 2020

Also a good reminder that I need a set_cookie() function (#795) so I don't have to mess around with SimpleCookie directly.

@simonw simonw closed this as completed in b5f04f4 Jun 9, 2020
@simonw
Copy link
Owner Author

simonw commented Jun 9, 2020

simonw added a commit that referenced this issue Jun 12, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant