# Authentication

> API keys for code, and OAuth sign-in for AI apps that connect to the MCP server. Both act inside one workspace.

Every request carries a key for one Forepop workspace in the Authorization header. Your own code uses an API key you make; AI apps that connect to the MCP server sign in with OAuth, which makes a key for them. Either way, the key acts as the person who made or allowed it, inside that one workspace only.

## API keys

- Make one at Settings, API keys (`/account/api-keys`). Admins and owners of a workspace can make keys; a key belongs to the workspace you're in when you make it.
- A key is `fp_live_` followed by 43 characters. It is shown once; Forepop keeps only a one-way fingerprint of it.
- A workspace can have up to 10 active keys, connected apps included.
- A key acts as the person who made it. If they leave the workspace, the key stops working (403).
- Revoke a key in the same place and it stops working at once.

Send it as a Bearer token:

```http
Authorization: Bearer fp_live_YOUR_KEY
```

```bash
curl https://forepop.com/api/v1/balance \
  -H "Authorization: Bearer fp_live_YOUR_KEY"
```

> Treat a key like a password. Anyone with it can start studies that spend your workspace's answers. Keep it in an environment variable or a secret store, never in shared files, prompts or screenshots.

## OAuth for AI apps

Apps such as Claude, ChatGPT, Claude Code, Codex, Gemini CLI and VS Code connect to the [MCP server](https://forepop.com/developers/mcp) by OAuth, so nobody copies a key. The person connecting signs in to Forepop, picks a workspace they are an admin or owner of, and presses Allow.

Forepop is a standard OAuth 2.1 authorization server for public clients. Clients discover it on their own from the MCP server's 401:

| What | Where |
| --- | --- |
| Protected resource metadata (RFC 9728) | `https://forepop.com/.well-known/oauth-protected-resource` |
| Authorization server metadata (RFC 8414) | `https://forepop.com/.well-known/oauth-authorization-server` |
| Dynamic client registration (RFC 7591) | `POST https://forepop.com/api/oauth/register` |
| Authorization (consent page) | `https://forepop.com/oauth/authorize` |
| Token | `POST https://forepop.com/api/oauth/token` |

- Grant: `authorization_code` with PKCE (`S256`) only. Public clients only: `token_endpoint_auth_method` is `none`.
- Scope: `studies`, which is starting and reading studies in one workspace and spending its answers.
- Redirect addresses must be https, or http to localhost for desktop apps.
- A code is good for 5 minutes and once only.
- The access token is an ordinary workspace API key. It does not expire and there is no refresh token; it lasts until it is revoked.
- Each connection shows under Settings, API keys as the app's name followed by "(connected)". Revoke it there to disconnect the app.

## When a key doesn't work

| Status | Code | Why |
| --- | --- | --- |
| 401 | `unauthorized` | No Authorization header, a malformed key, or a revoked one. The MCP server's 401 also names its OAuth metadata in `WWW-Authenticate`. |
| 403 | `forbidden` | The person who made the key is no longer in its workspace. |
| 429 | `rate_limited` | Too many requests; see [limits](https://forepop.com/developers/api#limits). |
