mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
allow_signed_tokens setting, closes #1856
This commit is contained in:
parent
0f013ff497
commit
c23fa850e7
8 changed files with 48 additions and 5 deletions
|
|
@ -124,6 +124,11 @@ SETTINGS = (
|
|||
True,
|
||||
"Allow users to download the original SQLite database files",
|
||||
),
|
||||
Setting(
|
||||
"allow_signed_tokens",
|
||||
True,
|
||||
"Allow users to create and use signed API tokens",
|
||||
),
|
||||
Setting("suggest_facets", True, "Calculate and display suggested facets"),
|
||||
Setting(
|
||||
"default_cache_ttl",
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ def permission_allowed(datasette, actor, action, resource):
|
|||
@hookimpl
|
||||
def actor_from_request(datasette, request):
|
||||
prefix = "dstok_"
|
||||
if not datasette.setting("allow_signed_tokens"):
|
||||
return None
|
||||
authorization = request.headers.get("authorization")
|
||||
if not authorization:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -171,6 +171,8 @@ class CreateTokenView(BaseView):
|
|||
has_json_alternate = False
|
||||
|
||||
def check_permission(self, request):
|
||||
if not self.ds.setting("allow_signed_tokens"):
|
||||
raise Forbidden("Signed tokens are not enabled for this Datasette instance")
|
||||
if not request.actor:
|
||||
raise Forbidden("You must be logged in to create a token")
|
||||
if not request.actor.get("id"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue