---
name: groundsocial-auth
description: How to get and use a Groundsocial credential, with no human (agent signup) or with one (dashboard, device login, OAuth for MCP clients), and how a person claims an agent's account.
metadata:
  version: 1.0.0
  canonical_url: https://groundsocial.dev/auth.md
---

# Groundsocial auth.md

## Numbered flow (start here)

1. **Discover**: `GET https://api.groundsocial.dev/.well-known/oauth-authorization-server` (or `https://api.groundsocial.dev/.well-known/oauth-protected-resource/mcp`). The metadata names the token, registration and authorization endpoints.
2. **Pick a method**
   - **Anonymous signup**: headless agent, no person present. Step 3.
   - **OAuth 2.1**: an MCP client where a person can open a browser. See OAuth below.
   - **Person**: dashboard at https://groundsocial.dev/app/sign-in (email code), or `groundsocial login` (device code).
3. **Register**: `POST https://api.groundsocial.dev/v1/agent/signup`. Store `api_key`; relay `claim_url` and `message_for_human` to a person.
4. **Claim**: the person opens `claim_url` in a browser and signs in. The account becomes theirs; the key keeps working.
5. **Call the API**: `Authorization: Bearer <key>` (or `x-api-key: <key>`) on `https://api.groundsocial.dev/v1/*`.

The API key is the credential for REST. There is no token exchange for REST calls.

## API keys

- Format `gs_live_…`, shown once when created. Only a hash is stored.
- Send as `Authorization: Bearer <key>` or `x-api-key: <key>`. Store as `GROUNDSOCIAL_API_KEY`.
- Each key can have a daily and a monthly spend cap in credits. A key can't raise its own caps; a capped key answers `402 spend_cap_reached`.
- Revoking a key stops it at once (and every OAuth connection made with it).

## Anonymous, claimable signup

```
POST https://api.groundsocial.dev/v1/agent/signup
Content-Type: application/json

{"agent_name": "optional", "purpose": "optional"}
```

| Answer | Meaning | Do |
| --- | --- | --- |
| `201` | `{api_key, key_id, account_id, credits, claim_url, claim_expires_at, message_for_human, docs}` | Store the key. Relay the message. |
| `428 challenge_required` | One short question in `error.details.challenge` (`token`, `question`, `expires_in`) | POST again with `challenge_token` and `answer` (one word from the question). Form fields `c` and `a` also work. |
| `428 challenge_failed` | Wrong or expired; a new question is attached | Answer the new one. |
| `429 signup_limited` | This network's daily signups are used | Wait `Retry-After`. Use the key you have. |
| `429 challenge_locked` | Too many questions from this network | Wait `Retry-After`. |
| `503 signup_disabled` | Signups are off | Stop and tell the person. |

New accounts get 100 free credits. Sign up only when there is no key at all.

## Claiming an account (people)

- `claim_url` (https://groundsocial.dev/claim/<token>) is browser-only. The person signs in with an email code and accepts. Accounts are never merged.
- Agents must never open, accept or automate a claim.

## Device login (CLI)

RFC 8628. `POST https://api.groundsocial.dev/v1/device/code` returns a `device_code`, a `user_code` and `https://groundsocial.dev/device`. The person enters the code there and approves. The CLI polls `POST https://api.groundsocial.dev/v1/device/token`: `authorization_pending` (keep polling), `slow_down` (poll less often), `access_denied`, `expired_token` (start again).

## OAuth 2.1 for MCP clients

- Authorization server metadata: `https://api.groundsocial.dev/.well-known/oauth-authorization-server`. Protected resource: `https://api.groundsocial.dev/.well-known/oauth-protected-resource/mcp`.
- Public clients only, PKCE S256 required. Dynamic client registration and client ID metadata documents are supported.
- Scopes: `reddit:read`, `account:read`. The person picks which account pays on the consent page.
- Each approved connection is a key named "<client> (MCP connection)": its spend caps apply, and revoking it disconnects the client.

## Keyless pay-per-call (rolling out)

A paid route called without a key will answer `402` with MPP (`WWW-Authenticate: Payment …`) and x402 offers for that call's price. Until then, a keyless call answers `401` with these signup instructions.

## Not supported

Confidential OAuth clients and client secrets, implicit and password grants, `client_credentials` for MCP, ID-JAG identity assertions, JWT access tokens and token introspection.
