{% extends "base.html" %} {% block title %}OAuth Clients{% endblock %} {% block content %}
Loading...
This Datasette instance supports OAuth 2.0 Authorization Code flow. Third-party applications can request scoped access tokens on behalf of users.
Use the form below to register your application. You will receive a client ID and client secret. The secret is only shown once — store it securely.
Send users to the authorization endpoint with these query parameters:
GET /-/oauth/authorize
?client_id=YOUR_CLIENT_ID
&redirect_uri=YOUR_REGISTERED_REDIRECT_URI
&response_type=code
&scope=SCOPES_JSON
&state=RANDOM_STATE
The scope parameter is a JSON array of scope arrays. Each scope
array has 1–3 elements:
["action"] — global permission (e.g. ["view-instance"])["action", "database"] — database-level (e.g. ["view-database", "mydb"])["action", "database", "resource"] — resource-level (e.g. ["view-table", "mydb", "users"])Example: [["view-instance"], ["view-table", "mydb", "users"]]
The state parameter should be a random string your app generates
to prevent CSRF. Verify it matches when receiving the callback.
After the user approves (or denies), they are redirected to your
redirect_uri with query parameters:
?code=AUTHORIZATION_CODE&state=YOUR_STATE?error=access_denied&state=YOUR_STATEMake a server-side POST to the token endpoint:
POST /-/oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=AUTHORIZATION_CODE
&client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
&redirect_uri=YOUR_REGISTERED_REDIRECT_URI
On success, you will receive:
{"access_token": "dstok_...", "token_type": "bearer"}
Include the token in API requests using the Authorization header:
Authorization: Bearer dstok_...
The token is scoped to only the permissions the user approved. Authorization codes expire after 10 minutes and can only be used once.