> ## Documentation Index
> Fetch the complete documentation index at: https://docs.boat.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Sign in with boat (OAuth)

> The boat version of "Sign in with GitHub". Your product uses another person's boat account, with their permission.

"Sign in with boat" works like "Sign in with GitHub". Your product can use **another person's** boat account. The person signs in to boat, sees what your product asks for, and selects what it gets. Your product never sees a password or an API key.

For your own account, use an [API key](https://docs.boat.dev/api-keys).

```mermaid theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
sequenceDiagram
  participant Product as Your product
  participant Person
  participant boat
  Product->>Person: 1. Open the boat link
  Person->>boat: 2. Sign in, select sandboxes, Allow
  boat-->>Product: 3. code
  Product->>boat: 4. code for tokens
  Product->>boat: 5. API calls with the access token
```

## 1. Create your OAuth app

An OAuth app is the client ID and the client secret of your product.

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat app create "Acme" --redirect-uri https://example.com/callback
```

boat prints the client ID and the client secret. It shows the secret once. You can also use **OAuth apps** in the [dashboard](https://boat.dev/dashboard?tab=apps).

| Your product runs | Command | Redirect URI |
| - | - | - |
| On a server | As above. It gets a secret. | `https` |
| On a device: CLI, desktop or mobile | Add `--no-secret` | `https`, or `http://localhost` on any port |

A product on a device calls boat directly. A web product calls boat from its server: boat does not answer browser requests from another site.

## 2. Send the person to boat

Make a random `code_verifier` and its SHA-256 hash, the `code_challenge` (PKCE). Keep the verifier.

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
CODE_VERIFIER=$(openssl rand -base64 64 | tr -d '=+/\n' | cut -c1-64)
CODE_CHALLENGE=$(printf '%s' "$CODE_VERIFIER" | openssl dgst -sha256 -binary | openssl base64 -A | tr '+/' '-_' | tr -d '=')
```

Open this URL in the person's browser:

```text theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
https://boat.dev/api/boat/oauth2/authorize
  ?response_type=code
  &client_id=boatapp_...
  &redirect_uri=https://example.com/callback
  &scope=account.read%20sandbox.read%20exec
  &state=RANDOM_VALUE
  &code_challenge=CODE_CHALLENGE
  &code_challenge_method=S256
```

boat sends the browser back to your redirect URI.

| The person | Your redirect URI gets |
| - | - |
| Allowed | `code`, `state`, `iss` |
| Cancelled | `error=access_denied`, `state`, `iss` |

Check that `state` is the value you sent.

## 3. Get the tokens

The code works once, for 5 minutes.

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
curl -sS https://boat.dev/api/boat/oauth2/token \
  -d grant_type=authorization_code \
  -d code="$CODE" \
  -d redirect_uri=https://example.com/callback \
  -d code_verifier="$CODE_VERIFIER" \
  -d client_id="$BOAT_CLIENT_ID" \
  -d client_secret="$BOAT_CLIENT_SECRET"
```

```json theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
{
  "access_token": "boat_...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "boatrt_...",
  "scope": "sandbox.read exec account.read"
}
```

An OAuth app without a secret leaves `client_secret` out.

## 4. Call the API

Use the access token like an API key:

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
curl -sS https://boat.dev/api/v1/me -H "Authorization: Bearer $ACCESS_TOKEN"
```

A call outside what the person allowed returns `403`. Read [scope errors](https://docs.boat.dev/api-keys/scopes.md#errors).

## 5. Refresh

The access token lasts 1 hour. Then:

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
curl -sS https://boat.dev/api/boat/oauth2/token \
  -d grant_type=refresh_token \
  -d refresh_token="$REFRESH_TOKEN" \
  -d client_id="$BOAT_CLIENT_ID" \
  -d client_secret="$BOAT_CLIENT_SECRET"
```

> [!WARNING]
>
> Each refresh returns a **new** refresh token. Save it and drop the old one. The old access token stops at once.
>
> If boat sees an old refresh token again after 1 minute, it disconnects your product from that account.

If the answer is lost, send the same request again within 1 minute.

Refresh from one place at a time. Two workers that refresh the same connection in parallel end it. The same applies to the code: exchange it once.

## Scopes

Ask for the smallest set. The person sees each one.

| Scope | Your product can |
| - | - |
| `account.read` | See the profile, plan, usage, organizations, API key names and CI logs. `GET /me` needs it: use it for "Sign in with boat". |
| `sandbox.read` | See sandboxes |
| `sandbox.create`, `sandbox.resume`, `sandbox.fork` | Create, resume or fork sandboxes. The person pays. |
| `sandbox.update`, `sandbox.stop` | Rename and share, or stop sandboxes |
| `sandbox.delete` | Delete sandboxes |
| `sandbox.delete-own` | Delete sandboxes it created |
| `agent.prompt` | Prompt agents in sandboxes |
| `exec` | Run commands in sandboxes |
| `file.read`, `file.write` | Read or write files in sandboxes |
| `ssh`, `desktop`, `host` | SSH, open the desktop, or publish ports |
| `network.write` | Change sandbox network rules |
| `snapshot.read`, `snapshot.write` | See and download snapshots, or create and delete them |
| `environment.read`, `environment.values.read`, `environment.write` | See environments, read their secrets, or change them |
| `billing.write` | See and change billing |

Each scope stands alone: no scope includes another, except that `sandbox.delete` covers `sandbox.delete-own`.

`environment.read` with `exec` or with `environment.write` also reads environment secrets. boat then adds `environment.values.read` to the request, shows it to the person, and returns it in `scope`.

Your product can never create API keys, change sign-in methods or delete the account.

The person can also limit your product:

| The person selects | Your product |
| - | - |
| One organization | Works in that organization only |
| Sandboxes | Reaches only those sandboxes, and cannot create new ones |
| Environments | Reaches the sandboxes in them, and can create sandboxes there |

## Manage OAuth apps

| You want to | CLI | Dashboard |
| - | - | - |
| See connected products and your OAuth apps | `boat app list` | **OAuth apps** |
| Disconnect a product from your account | `boat app disconnect "Acme"` | **OAuth apps** > **Disconnect** |
| Change redirect URIs | `boat app update "Acme" --redirect-uri https://example.com/cb2` | **OAuth apps** > **Edit URIs** |
| Replace the secret | `boat app secret "Acme"` | **OAuth apps** > **New secret** |
| Delete your OAuth app | `boat app delete "Acme"` | **OAuth apps** > **Delete** |

These commands need a browser login (`boat login`), not an API key.

* Disconnect stops the tokens of the product at once.
* Delete disconnects every user of your product.
* Your product can also give up its own access: `curl -sS https://boat.dev/api/boat/oauth2/revoke -d token="$REFRESH_TOKEN"`

## Reference

| Endpoint | URL |
| - | - |
| Authorize | `https://boat.dev/api/boat/oauth2/authorize` |
| Token | `https://boat.dev/api/boat/oauth2/token` |
| Revoke | `https://boat.dev/api/boat/oauth2/revoke` |
| Metadata (RFC 8414) | `https://boat.dev/.well-known/oauth-authorization-server` |

Token errors are `{"error": "...", "error_description": "..."}`:

| `error` | Meaning |
| - | - |
| `invalid_client` (401) | Wrong client ID or client secret |
| `invalid_grant` (400) | The code or the refresh token is wrong, expired, used or revoked. Or `redirect_uri` or `code_verifier` does not match. |
| `invalid_scope` | A scope is unknown or not available to OAuth apps. It comes back on your redirect URI. |

Limits: 10 OAuth apps per account, 10 redirect URIs per OAuth app. boat matches the redirect URI exactly, except the port of a `localhost` URI. An OAuth app name cannot contain "boat".

Keep the client secret and the refresh tokens on your server. Never put a token in a URL or a log.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.