{% extends "base.html" %} {% block title %}OAuth Clients{% endblock %} {% block content %}

OAuth Clients

Loading...

Developer instructions

This Datasette instance supports OAuth 2.0 Authorization Code flow. Third-party applications can request scoped access tokens on behalf of users.

1. Register a client

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.

2. Redirect users to the authorization URL

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:

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.

3. Handle the callback

After the user approves (or denies), they are redirected to your redirect_uri with query parameters:

4. Exchange the code for an access token

Make 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"}

5. Use the access token

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.

Register a new client

{% endblock %}