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

> ## Agent Instructions
> If the user asks to make Context.dev their default search and scrape provider, follow https://docs.context.dev/default-search-scrape.md. For other setup requests, follow https://docs.context.dev/agent-quickstart.md and start by signing the user up and getting an API key through https://www.context.dev/auth.md. During setup, use the relevant guide already in context instead of fetching it again or loading the full documentation index. Application code reads CONTEXT_DEV_API_KEY.

# OAuth reference

> Endpoints, parameters, scopes, token lifetimes, and errors for Context.dev OAuth apps.

Context.dev supports the OAuth 2.0 authorization code flow with PKCE and rotating refresh tokens.

## Endpoints

| Endpoint | URL |
| - | - |
| Authorization | `https://www.context.dev/oauth2/authorize` |
| Token | `https://www.context.dev/oauth2/token` |
| Revocation | `https://www.context.dev/oauth2/revoke` |
| Metadata | `https://www.context.dev/.well-known/oauth-authorization-server` |

## Authorization request

Redirect the user's browser to the authorization endpoint with these query parameters.

| Parameter | Required | Notes |
| - | - | - |
| `response_type` | Yes | `code`. |
| `client_id` | Yes | Your app's client ID. |
| `redirect_uri` | Yes | One of the app's registered redirect URIs. |
| `code_challenge` | Yes | The Base64url-encoded SHA-256 hash of your code verifier. |
| `code_challenge_method` | Yes | `S256`. |
| `scope` | No | Space-separated [scopes](#scopes). Defaults to `data:execute`. |
| `state` | No | Returned unchanged. Use it to stop forged callbacks. |
| `logo_uri` | No | An HTTPS image on the same origin as `redirect_uri`, shown on the consent screen. |

The code verifier is 43 to 128 characters from `A-Z`, `a-z`, `0-9`, `-`, `.`, `_`, and `~`.

Context.dev redirects to `redirect_uri` with `code` and `state`. If the user cancels, it redirects with `error=access_denied`, `error_description`, and `state` instead.

An invalid request is shown to the user on Context.dev with the reason, so you can fix it while you build. Once your app is verified, invalid requests are returned to your `redirect_uri` with one of the errors below. A request with an unknown `client_id` or an unregistered `redirect_uri` is never redirected.

| `error` | Cause |
| - | - |
| `access_denied` | The user cancelled. |
| `invalid_scope` | `scope` contains a value your app cannot request. |
| `invalid_request` | A parameter is missing, repeated, or malformed, or PKCE is not `S256`. |
| `unsupported_response_type` | `response_type` is not `code`. |

## Token request

Send a `POST` to the token endpoint, form-encoded or as JSON.

| Parameter | Code exchange | Refresh |
| - | - | - |
| `grant_type` | `authorization_code` | `refresh_token` |
| `client_id` | Required | Required |
| `client_secret` | Required for server apps | Required for server apps |
| `code` | Required | |
| `code_verifier` | Required | |
| `redirect_uri` | Required. The same value as in the authorization request. | |
| `refresh_token` | | Required |

```json theme={null}
{
  "access_token": "ctxt_oat_...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "data:execute profile",
  "refresh_token": "ctxt_ort_...",
  "organization_id": "...",
  "user": {
    "id": "...",
    "email": "ada@example.com",
    "email_verified": true,
    "name": "Ada Lovelace"
  }
}
```

| Field | Notes |
| - | - |
| `access_token` | Send as `Authorization: Bearer <token>`, the same as an API key. |
| `expires_in` | Seconds until the access token expires. |
| `scope` | The scopes the user approved for this token. |
| `refresh_token` | Replaces the refresh token you used. |
| `organization_id` | The workspace the user picked. Usage draws on its credits, plan, and rate limits. |
| `user` | Present only when the token has the `profile` scope. `name` is omitted when the account has none. |

| Token error | Status | Cause |
| - | - | - |
| `invalid_client` | `401` | Unknown client ID, or a wrong or missing client secret. |
| `invalid_grant` | `400` | The code or refresh token is expired, already used, or was issued to another client, the PKCE verifier does not match, or the connection ended. |
| `invalid_scope` | `400` | A refresh asked for a scope your app cannot request. |
| `unsupported_grant_type` | `400` | `grant_type` is not supported. |

Errors use the standard OAuth shape, `{"error": "...", "error_description": "..."}`.

## Revocation

Send a `POST` to the revocation endpoint with `token` set to the current refresh token. That ends the connection, so every token issued for it stops working, including tokens on the user's other devices.

An access token works too while it is still valid. A refresh token that was already replaced, an expired access token, and an unknown token are all ignored, and the endpoint still returns `200`.

## Scopes

| Scope | Grants |
| - | - |
| `profile` | The user's account ID, verified email, and name in the token response. No API access. |
| `data:execute` | Calling the data APIs, such as scrape, search, and enrichment. |
| `logs:read` | Reading usage and request logs. |
| `monitors:read` | Reading monitors, runs, and changes. |
| `monitors:write` | Creating, updating, running, and deleting monitors, including their webhook URLs and signing secrets. Includes `monitors:read`. |
| `batches:read` | Reading batches and their results. |
| `batches:write` | Submitting and cancelling batches. Includes `batches:read`. |
| `access_policies:read` | Reading access policies. |
| `access_policies:write` | Creating, updating, and deleting access policies. Includes `access_policies:read`. |

Apart from `profile`, scopes match [API key permissions](https://docs.context.dev/account/api-keys.md#choose-permissions), with one exception: an OAuth app can't list or use saved [browser profiles](https://docs.context.dev/scrape/browser-profiles.md). A request that sets `sharedParams.profile`, or calls `GET /org/browser/profiles`, returns `403`.

## Lifetimes

| Item | Lifetime |
| - | - |
| Authorization code | Five minutes, single use. |
| Access token | One hour. |
| Refresh token | 30 days from its last use. Each refresh returns a new one, and the one you used stops working. Using a replaced refresh token again more than a minute later ends the connection. |

## Connections

* A connection is one person's approval of your app for one workspace and one set of scopes. A token can do exactly what its consent screen listed.
* Approving the same scopes again reuses the connection. Approving different scopes creates a separate connection and leaves the first one unchanged.
* Tokens from separate approvals of the same scopes, such as two devices, all stay valid and share the connection.
* A connection ends right away when your app revokes a token, the user disconnects on their [Connected apps page](https://context.dev/dashboard/connected-apps), or the user disables or deletes the connection's key on their [API keys page](https://context.dev/dashboard/api-keys).
* A connection stops refreshing when the user leaves the workspace or you delete the app. Access tokens already issued work until they expire, within the hour.
* Monitors and batches your app created belong to the workspace. They keep running after the connection ends, until the user stops them.

## API responses

| Status | Meaning |
| - | - |
| `401` | The access token is expired or unknown, or the connection ended. The message says to refresh the token. |
| `402` | The workspace is out of credits. See [credits](https://docs.context.dev/account/credits.md). |
| `403` | The call needs a scope the connection does not have, or uses a saved browser profile. |


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