-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manage tokens mode: UI for creating database-backed tokens with restricted permissions #7
Comments
Here's the ambitious plan for this feature:
The most ambitious version:
That last feature is my dream feature for API tokens, but I don't know how feasible it is to implement. |
First attempt at schema design: CREATE TABLE _datasette_auth_tokens (
id INTEGER PRIMARY KEY,
secret TEXT,
permissions TEXT,
actor_id TEXT,
created_timestamp INTEGER,
last_used_timestamp INTEGER
); |
I'm going to turn this mode on with a plugin configuration option: plugins:
datasette-auth-tokens:
manage_tokens: true Where |
Updated schema: CREATE TABLE _datasette_auth_tokens (
id INTEGER PRIMARY KEY,
secret TEXT,
description TEXT,
permissions TEXT,
actor_id TEXT,
created_timestamp INTEGER,
last_used_timestamp INTEGER,
expires_after_seconds INTEGER
); Now has And |
Moving the work on this to a PR. |
I started work on a view for this before deciding that it would be better to use an existing table implementation: async def list_tokens(request, datasette):
_check_permission(datasette, request)
db = datasette.get_database()
tokens = []
for row in (
await db.execute(
"select id, description, permissions, created_timestamp, expires_after_seconds "
"from _datasette_auth_tokens where actor_id = :actor_id order by id desc",
{"actor_id": request.actor["id"]},
)
).rows:
tokens.append(
{
"id": row[0],
"description": row[1],
"permissions": json.loads(row[2]),
"created_timestamp": row[3],
"expires_after_seconds": row[4],
}
)
context = await _shared(datasette, request)
context.update({"tokens": tokens, "datasette": datasette})
return Response.html(
await datasette.render_template(
"list_api_tokens.html", context, request=request
)
) |
System should show a custom "token is revoked" or "token has expired" error. |
I wanted to So I return |
Spotted a problem while working on this: if you grant a token access to view table for a specific table but don't also grant view database and view instance permissions, that token is useless. This was a deliberate design decision in Datasette - it's documented on https://docs.datasette.io/en/1.0a2/authentication.html#access-permissions-in-metadata
I'm now second-guessing if this was a good decision. |
Potential workaround: I could set the actor to |
I need this for Datasette Cloud. This would be a database-backed alternative to the new default signed token UI added in Datasette 1.0:
The text was updated successfully, but these errors were encountered: