# Firedrill account access

Firedrill is a simulation platform for AI agents. Your agent runs locally; reusable worlds, tools, personas, scenarios and reports remain in the cloud. Account creation does not require a credit card, checkout, paid subscription or automatic top-up. Resource allowances depend on the workspace's current entitlement.

Give a first-time user the [Firedrill portal](https://app.firedrill.run/signin) to create their workspace and personally review its name, terms and privacy policy. Then select that existing workspace during terminal or MCP authorization. Do not create another workspace while a previously submitted request is unresolved.

For a terminal, `firedrill signup` uses the supported browser device-authorization flow. Keep that original pending attempt until it is approved, denied or expires. WorkOS verifies the person. Optional profile fields can be skipped. Workspace selection and required terms still apply.

Where terminal workspace creation is supported, read `GET /api/auth/native/workspace-policy` first. If the policy is unavailable and there is no unresolved request, use the portal. If the policy is available, obtain the person's explicit approval of the workspace, terms and privacy policy. Then send `POST /api/auth/native/workspace-requests` with the original request UUID in the `Idempotency-Key` header and the JSON fields `name`, `workspace_consent`, `terms_version`, `terms_accepted`, `privacy_version` and `privacy_accepted`. Use the policy's current versions; acceptance fields require the person's actual approval, never an automatic default. Recover an interrupted request with `GET /api/auth/native/workspace-requests/<original-request-uuid>`, not a new UUID. Creating a new organization requires new organization-bound authorization; it does not change the current token's scope. An existing organization-bound MCP connection cannot create organizations through this terminal endpoint.

For remote MCP, use `https://mcp.firedrill.run` and its protected-resource metadata. The verified claim and configured registration policy grant `firedrill:read` for reading and `firedrill:write` for changes, subject to the user's current workspace permissions. An agent cannot grant itself additional permissions by requesting scope names.

When exchanging the identity assertion for an MCP access token in the hosted instructions below, set `RESOURCE="https://mcp.firedrill.run"` and include `resource=https://mcp.firedrill.run` in the token request. This resource is required for Firedrill MCP even if the generic hosted instructions describe it as optional. Omitting it selects the default application audience, which Firedrill MCP does not accept.

Use `service_auth` registration to access remote MCP for an account with an existing workspace. Registration endpoints and supported identity types are advertised in the issuer's `agent_auth` metadata and hosted instructions, separately from its standard OAuth `grant_types_supported`. Use only the advertised methods and endpoints. Firedrill MCP accepts short-lived access tokens for its exact resource, not identity assertions or durable registration API keys. An email is only a login hint, not identity proof. Anonymous or unclaimed registrations cannot access Firedrill tenant data. Provider-attested identity is usable only when the configured service explicitly advertises it; an agent cannot invent an assertion issuer.

Follow the exact hosted claim ceremony. Some hosted flows ask the user to read a code from the verification page back to the client; device flows display a code to the user and poll. Do not substitute one for the other. Keep assertions, claim handles and bearer credentials in the intended client's private credential store, never logs or source files. Billing/payment authorization is separate.

## Hosted registration instructions

# auth.md — agent registration

You are an agent. This service allows you to register for an identity and exchange it for credentials.

Run these commands in order. **Don't print secret values and don't write your own scripts** — the commands below persist secrets and surface only non-secret fields. Commands are macOS (`curl`, `security`, `jq`); adapt as needed for Linux (`secret-tool`, reads stdin) or Windows (PowerShell `Set-Secret`/`Get-Secret`). Only `security` takes the secret on argv — `secret-tool`/`Set-Secret` don't, so don't carry its "rotate if exposed" caveat to them.

Set once:

```bash
ISSUER="https://signin.firedrill.run"
SVC="${ISSUER#https://}"        # keychain service label (issuer host)
EMAIL="<user-email>"           # login_hint, and keychain account for email-based methods
```

## 1. Check for an existing registration — reuse before creating a new one

```bash
if   security find-generic-password -s "$SVC" -a "$EMAIL"  -w >/dev/null 2>&1; then ACCT="$EMAIL"
fi
# ACCT set -> skip to step 4 (Exchange). ACCT unset -> continue to step 2.
```

## 2. Register — pick the method that fits; capture into `$REG`, never print it

```bash
# service_auth — you have the user's email (claim ceremony required):
REG="$(curl -sS "$ISSUER/agent/identity" -H 'Content-Type: application/json' \
  -d "{\"type\":\"service_auth\",\"login_hint\":\"$EMAIL\"}")"
ACCT="$EMAIL"
# errors: invalid_request -> fix the body; invalid_login_hint -> fix EMAIL; service_auth_registration_disabled -> method not enabled for this environment.
```

**Don't persist `$REG` yet** — the service_auth response holds only a short-lived `claim.token`. Keep it in memory; persist after the claim verifies (step 3).

## 3. Claim ceremony — service_auth (required)

Mint an attempt and give the user its link. They sign in there and the page shows them a code; once they read it back to you, complete the claim with it.

```bash
CLAIM_TOKEN="$(printf '%s' "$REG" | jq -r .claim.token)"
ATT="$(curl -sS "$ISSUER/agent/identity/claim" -H 'Content-Type: application/json' \
  -d "{\"type\":\"service_auth\",\"claim_token\":\"$CLAIM_TOKEN\",\"login_hint\":\"$EMAIL\"}")"
# errors: invalid_claim_token -> restart at step 2; invalid_login_hint -> fix EMAIL; claim_expired | claim_revoked | already_claimed -> restart at step 2; auth_method_disabled -> method was disabled; too_many_attempts -> wait for a pending attempt to expire.

# give the user this link (non-secret); the code is shown to them on the page, not here:
printf '%s' "$ATT" | jq '{verification_uri:.attempt.verification_uri}'

# the user reads the code off that page and gives it to you; submit it with the claim token:
USER_CODE="<code the user read off the claim page>"
VER="$(curl -sS "$ISSUER/agent/identity/claim/complete" -H 'Content-Type: application/json' \
  -d "{\"claim_token\":\"$CLAIM_TOKEN\",\"user_code\":\"$USER_CODE\"}")"

# success returns the verified identity once — persist it; an error returns {code,message}:
printf '%s' "$VER" | jq -e .identity.assertion >/dev/null && security add-generic-password -U -s "$SVC" -a "$ACCT" -w "$VER"
# errors: claim_not_confirmed -> user hasn't finished on the page yet, wait and retry; invalid_user_code -> wrong code, ask the user again; user_code_expired -> re-run this step for a fresh link; claim_expired | already_claimed -> restart at step 2; claim_denied -> user denied the claim, restart at step 2; auth_method_disabled -> method was disabled; organization_selection_required | stale_organization_selection -> user must re-select an organization on the claim page.
```

## 4. Exchange the assertion for an access token

```bash
ASSERTION="$(security find-generic-password -s "$SVC" -a "$ACCT" -w | jq -r .identity.assertion)"
RESOURCE="<resource-uri>"   # optional — binds the token's aud to a resource this service recognizes; omit both resource lines for the default audience
CRED="$(curl -sS "$ISSUER/oauth2/token" -H 'Content-Type: application/x-www-form-urlencoded' \
  -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \
  --data-urlencode "assertion=$ASSERTION" \
  --data-urlencode "resource=$RESOURCE")"
ACCESS_TOKEN="$(printf '%s' "$CRED" | jq -r .access_token)"
# errors: invalid_request -> assertion could not be decoded; invalid_grant -> assertion expired/revoked, restart at step 2; invalid_target -> resource URI not recognized; unsupported_grant_type -> use the grant above.
```

Send it as `Authorization: Bearer $ACCESS_TOKEN`. **Don't persist the access token** — it's short-lived (~5 minutes). When it expires, re-run this step from the stored assertion; when the assertion itself expires, refresh (step 5).

## 5. Refresh — when the stored assertion nears expiry

```bash
RT="$(security find-generic-password -s "$SVC" -a "$ACCT" -w | jq -r .identity.refresh_token.value)"
REG="$(curl -sS "$ISSUER/agent/identity" -H 'Content-Type: application/json' \
  -d "{\"type\":\"refresh\",\"refresh_token\":\"$RT\"}")"
security add-generic-password -U -s "$SVC" -a "$ACCT" -w "$REG"   # rotates the refresh token; overwrite
# errors: invalid_refresh_token -> restart at step 2.
```

Then re-run step 4 with the fresh assertion.

## 6. Revoke — when the registration is no longer needed

```bash
RT="$(security find-generic-password -s "$SVC" -a "$ACCT" -w | jq -r .identity.refresh_token.value)"
curl -fsS "$ISSUER/oauth2/revoke" -H 'Content-Type: application/x-www-form-urlencoded' \
  -d token_type_hint=refresh_token --data-urlencode "token=$RT" \
  && security delete-generic-password -s "$SVC" -a "$ACCT" >/dev/null   # forget it only once the server said 200
# 200 means the registration is gone (also returned for an unknown or already-revoked token). 5xx -> nothing is deleted; back off and retry.
```

This revokes the whole registration — the assertion, the refresh token, and every access token minted from it — and can't be undone; restart at step 2 for a new identity. To revoke a single access token and keep the registration, send it with `token_type_hint=access_token`.

## Any request

`5xx` -> back off and retry the same request. `rate_limit_exceeded` -> wait `retry_after` seconds. A `4xx` not listed above -> fix per the response body; don't replay.
