# External Auth Providers

> External Auth Providers — Turso documentation.
> Canonical HTML: https://tursodb.cn/docs/sdk/authorization/jwks/
> Upstream Source (MIT): https://docs.turso.tech/sdk/authorization/jwks
> Language: en

---
Instead of managing tokens manually, you can let your authentication provider issue JWT tokens using JWKS. This allows you to leverage your existing auth infrastructure (e.g., Clerk, Auth0).

<div class="doc-callout doc-callout-info"><div class="doc-callout-title">NOTE</div><div class="doc-callout-body">

During the Turso Beta, we only support Clerk & Auth0 as OIDC providers.

</div></div>


**1. Generate JWT Template**

Use the Turso CLI to generate a JWT claims template for your auth provider:

```bash
# Full access to a database
turso org jwks template --database <database-name> --scope full-access

# Read-only access to a group
turso org jwks template --group <group-name> --scope read-only

# Fine-grained permissions
turso org jwks template \
  --database <database-name> \
  --permissions all:data_read \
  --permissions comments:data_add
```

Copy the generated template into your auth provider's JWT configuration.

**2. Add JWKS Endpoint to Turso**

Register your auth provider's JWKS endpoint with your Turso organization:

```bash
turso org jwks save <name> <url>
```

For example, with Clerk:

```bash
turso org jwks save clerk https://your-app.clerk.accounts.dev/.well-known/jwks.json
```

You can also add JWKS endpoints in the [Turso Dashboard](https://turso.tech/app) under organization settings.

**3. Use Tokens in Your Application**

Get the JWT from your auth provider and pass it as the `authToken`:

```javascript
import { connect } from "@tursodatabase/serverless";

const authToken = await getAuthToken(); // e.g., from Clerk, Auth0

const db = connect({
  url: "<your-database-url>",
  authToken,
});
```

## Managing JWKS Endpoints

```bash
# List all JWKS endpoints
turso org jwks list

# Remove a JWKS endpoint
turso org jwks remove <name>
```

<div class="doc-callout doc-callout-warning"><div class="doc-callout-title">WARNING</div><div class="doc-callout-body">

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.

</div></div>
