# StrawPoll auth.md

This file tells AI agents how to get credentials for StrawPoll, which makes polls, meeting
polls and forms. There are two ways in:

- **OAuth** for the MCP server at https://strawpoll.com/mcp: you register yourself as a client, a person
  signs in and approves you, and you get an access token that acts for them.
- **An API key** that a person creates and gives you. It works on the MCP server and on the
  REST API at https://strawpoll.com/api/v4.

StrawPoll has no agent identity endpoint and does not accept ID-JAG assertions or verified-email
registration. Registration is anonymous (an OAuth client with no owner) until a person claims it
by approving it.

## 1. Discover

Call the MCP server without a token. It answers `401` with:

```http
WWW-Authenticate: Bearer resource_metadata="https://strawpoll.com/.well-known/oauth-protected-resource/mcp", scope="polls"
```

Fetch that protected resource metadata (also at https://strawpoll.com/.well-known/oauth-protected-resource),
then the metadata of the authorization server it names:

```http
GET https://strawpoll.com/.well-known/oauth-authorization-server/api/auth
```

Its `agent_auth` block lists `register_uri`, `claim_uri` and `revocation_uri`. If this file
and the metadata disagree, the metadata wins.

## 2. Pick a method

- You can open a browser for the person, or show them a link: use OAuth (steps 3 to 5).
- You can't, or you need the REST API: ask the person for an API key (step 6).

## 3. Register (anonymous)

Register once and keep the `client_id`. Public clients use PKCE and no secret:

```http
POST https://strawpoll.com/api/auth/oauth2/register
Content-Type: application/json

{
  "client_name": "Your agent",
  "redirect_uris": ["http://127.0.0.1:33418/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none"
}
```

```json
{ "client_id": "…", "client_id_issued_at": 1700000000, "redirect_uris": ["http://127.0.0.1:33418/callback"] }
```

Clients that publish a Client ID Metadata Document can skip this and use its URL as their
`client_id`.

## 4. Claim: the person signs in and approves

Send the person to the authorization endpoint with a PKCE challenge (S256 only):

```http
GET https://strawpoll.com/api/auth/oauth2/authorize?response_type=code&client_id=<client_id>&redirect_uri=<redirect_uri>&scope=polls%20offline_access&resource=https%3A%2F%2Fstrawpoll.com%2Fmcp&code_challenge=<challenge>&code_challenge_method=S256&state=<state>
```

They sign in to StrawPoll (or create an account) and approve your client on the consent page.
That ties your client to their account. Their browser comes back to your `redirect_uri` with a
`code`.

## 5. Get and use the token

```http
POST https://strawpoll.com/api/auth/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=<code>&redirect_uri=<redirect_uri>&client_id=<client_id>&code_verifier=<verifier>&resource=https%3A%2F%2Fstrawpoll.com%2Fmcp
```

Call the MCP server with `Authorization: Bearer <access_token>`. The token needs the
`polls` scope and is only for https://strawpoll.com/mcp. With `offline_access` you also get a
`refresh_token`; renew with `grant_type=refresh_token` at the same endpoint.

## 6. API key

The person creates a key at https://strawpoll.com/settings#api-keys and gives it to you. Send it as:

```http
X-API-Key: <key>
```

`Authorization: Bearer <key>` works too. A read-only key can list polls and read results;
on the MCP server it only gets the tools that change nothing. The REST API is documented at https://strawpoll.com/docs/api.

## Errors

| Status | Meaning | What to do |
| --- | --- | --- |
| 401 | No token, an expired token, or an invalid API key | Refresh the token, or start again at step 1 |
| 403 | The token lacks the `polls` scope (`error="insufficient_scope"`) | Authorize again with that scope |
| 429 | Rate limited | Wait for `Retry-After` seconds |

## Revocation

Revoke tokens you no longer need (RFC 7009), authenticating as the metadata's
`revocation_endpoint_auth_methods_supported` lists:

```http
POST https://strawpoll.com/api/auth/oauth2/revoke
Content-Type: application/x-www-form-urlencoded

token=<token>&token_type_hint=refresh_token
```

A person can delete an API key in their settings at any time; requests with it then get `401`.
