Overview
Turso supports authorization through JWT tokens issued by your authentication provider. You can either:- Create database or group tokens via Turso CLI
- Let your authentication provider issue tokens using JWKS
During the Turso Beta, we only support Clerk & Auth0 as OIDC providers.
1
Setup Authentication Provider
First, configure your authentication provider to issue JWT tokens. This example uses Clerk.Available flags:
Configure JWT Permissions
Use the Turso CLI to generate a JWT template with fine-grained permissions:--database
or-d
: Specify the database name (required if--group
not specified)--group
or-g
: Specify the group name (required if--database
not specified)--scope
or-s
: Set scope tofull-access
orread-only
--permissions
or-p
: Define table-level permissions in format<table-name|all>:<action1>,<action2>
--permissions
:data_read
- Read data from tablesdata_update
- Update existing datadata_add
- Insert new datadata_delete
- Delete dataschema_update
- Modify table schemasschema_add
- Create new tablesschema_delete
- Drop tables
data_read
is allowed on SQLite system tables (e.g., sqlite_master
,
sqlite_schema
) by default, allowing users to query database metadata.Either
--database
or --group
must be specified when generating a JWT
template.Configure JWT Template
Set up a JWT template in your auth provider to include permissions based on user metadata. This allows you to control access at the table and action level.For example, you can configure your JWT template to:- Grant admin users
data_delete
permissions - Grant moderator users
data_update
anddata_read
permissions - Grant regular users
data_read
permissions only
If you don’t setup a JWT template with specific permissions, the generated
tokens will have access to all databases in all groups by default.
2
Add JWKS Endpoint to Turso
Add your authentication provider’s JWKS endpoint to your Turso organization.Example:
Using the CLI
Using the Dashboard
Navigate to your organization settings in the Turso Dashboard and add the JWKS endpoint URL.3
Use Tokens in Your Application
Pass the JWT token from your authentication provider when creating the database client:The
authToken
can be:- A JWT token issued by your authentication provider (via JWKS)
- A database token created with
turso db tokens create <db>
- A group token for accessing multiple databases