# auth.md

How a software agent authenticates to Flitch.

## What you are authenticating to

Flitch runs an MCP server at `https://app.flitch.io/api/mcp`, scoped to one
workspace. Its tools list spaces, datasets, data sources and published
artifacts, answer questions of data already connected to Flitch, and, where the
person allowed it, build, edit and publish a dashboard, report or app on that
data, add a table from CSV, rename, describe or schedule datasets, and start
connecting a data source by handing the person a link to Flitch's own form.
There is also a REST API under `https://app.flitch.io/api/v1`, described at
<https://flitch.io/openapi.json>.

## Discovery

Both documents are live and authoritative. Where this page and they disagree,
believe them.

- Protected resource metadata (RFC 9728):
  <https://flitch.io/.well-known/oauth-protected-resource>
- Authorization server metadata (RFC 8414):
  <https://flitch.io/.well-known/oauth-authorization-server>

A request to the MCP endpoint without a token answers `401` with a
`WWW-Authenticate` header pointing at the first of those, so you can start
from the endpoint and never read this page.

## Registering

Dynamic client registration is open, so an agent registers itself rather than
asking a person for credentials.

```json
{
  "agent_auth": {
    "skill": "https://flitch.io/.well-known/agent-skills/flitch-data/SKILL.md",
    "register_uri": "https://app.flitch.io/api/auth/oauth2/register",
    "methods": [
      {
        "type": "oauth2",
        "grant_types": ["authorization_code", "refresh_token"],
        "response_types": ["code"],
        "code_challenge_methods": ["S256"],
        "authorization_uri": "https://app.flitch.io/api/auth/oauth2/authorize",
        "token_uri": "https://app.flitch.io/api/auth/oauth2/token",
        "scopes": ["data:read", "data:write", "artifacts:read", "artifacts:write"],
        "token_endpoint_auth_methods": ["none", "client_secret_basic", "client_secret_post", "private_key_jwt"],
        "bearer_methods": ["header"]
      }
    ]
  }
}
```

## Using the token

Send it as `Authorization: Bearer <token>`. Scopes are enforced per tool and
per route, and a call outside the granted scopes is refused with a message
naming the scope it needed, so an agent can ask to reconnect rather than guess.

## What a connection can reach

The workspaces the person ticked when they approved it, and nothing outside
them; the connection works in one at a time and switches with `use_space`. A
person can revoke a connection at any time from their Flitch settings, after
which every token for it stops working. Building, editing, publishing,
copying, restoring a version and running a workflow need the `artifacts:write` scope, which the person grants
at consent and which draws on the workspace's balance. Adding a table, changing
a dataset's name, description or refresh schedule, starting a source
connection and bringing its tables in need `data:write`. No tool takes a
credential: connecting a source returns a link
to Flitch's own form, where the person types the secret or signs in; a webhook
receiver, which needs no secret, is made at once, and a connected source's
tables or objects can be brought in as datasets without the form. Anything
a tool cannot finish itself comes back the same way: a link to the exact place
in Flitch, the steps to take there, and what to call once the person is back.
