simonw / django-plugin-datasette

Django plugin to run Datasette inside of Django
Apache License 2.0
6 stars 0 forks source link

Optional authentication #4

Open simonw opened 1 month ago

simonw commented 1 month ago

Would be good if users could say that only e.g. Django staff members could access /-/datasette/...

simonw commented 1 month ago

I think the trick here will be to use the django.contrib.auth.get_user or .aget_user() methods: https://github.com/django/django/blob/5ed72087c450af1a5da138bdfa674a069cf3f09c/django/contrib/auth/__init__.py#L200

These both take a Django request though, so may need to figure out how to turn ASGI scope into a Django request object - probably using this: https://github.com/django/django/blob/5ed72087c450af1a5da138bdfa674a069cf3f09c/django/core/handlers/asgi.py#L48