# s.pfos.school auth.md

s.pfos.school is the URL shortener of PFOS.school. This file tells AI agents and scripts how to call it with an identity, and when they need none. The protected resource metadata at https://s.pfos.school/.well-known/oauth-protected-resource says the same in JSON; if the two ever disagree, the metadata wins.

## Who this is for

- AI agents, scripts and apps that call the REST API (`https://s.pfos.school/api/v1/...`), the MCP server (`https://s.pfos.school/mcp`) or the A2A agent (`https://s.pfos.school/api/v1/a2a`, card: https://s.pfos.school/.well-known/agent-card.json).
- People do not need this file: they sign in on https://s.pfos.school with the "login" link at the top right.

## No registration: anonymous use

The public features need no account, no key and no registration. Just call them:

- `POST /api/v1/public/links` with `{"url": "..."}` makes a short link, `POST /api/v1/qr` a QR code with a logo, `GET /{code}.svg` and `GET /{code}.png` the QR code of a link, and `GET /api/v1/me` tells who you are (`{"signedIn": false, ...}`).
- The MCP tools `shorten_url` and `get_qr_code` and the A2A skill `shorten-url` work the same way.
- Anonymous limits, per IP address: 30 links per minute on `POST /api/v1/public/links`, 30 on MCP `shorten_url` and 30 on the A2A agent (each counted on its own), 30 QR codes per minute on `POST /api/v1/qr`. Every response of `/api/v1` carries `RateLimit-Policy`.
- Links are public and permanent. Never shorten URLs that contain secrets or personal information.

## With an identity

An identity puts the links you create into an account's history (`GET /api/v1/me/links`) and raises the limits four times, to 120 per minute, counted per account. Two kinds of credential work.

### pfos-ID access tokens (OAuth 2.0)

pfos-ID (https://id.pfos.school) is the account system of PFOS and the authorization server of this API.

- Resource: `https://s.pfos.school`. Send it as `resource` (RFC 8707) when you ask for the token; it becomes the token's `aud`.
- Authorization server: `https://id.pfos.school`. Its metadata: https://id.pfos.school/.well-known/oauth-authorization-server
- Scopes:
  - `links:read`: read the links the account created (`GET /api/v1/me/links`)
  - `links:write`: create short links and QR codes as the account (`POST /api/v1/public/links`, `POST /api/v1/qr`, MCP `shorten_url`, the A2A agent) and take links out of its history (`DELETE /api/v1/me/links/{code}`)
  - `GET /api/v1/me` takes either. Ask only for what you use.
- A narrower resource for the QR code designer (the page https://s.pfos.school/qr): `https://s.pfos.school/qr`, metadata at https://s.pfos.school/.well-known/oauth-protected-resource/qr. A token for `resource=https://s.pfos.school/qr` carries `links:write` only and works only for the two calls of that page, `POST /api/v1/public/links` and `POST /api/v1/qr`; every other endpoint refuses it (`401 invalid_token`). Ask for `resource=https://s.pfos.school` unless those two calls are all you need.
- Access tokens are JWTs and live 10 minutes. This site checks them itself, without asking pfos-ID, so a revoked token keeps working until it expires.

There are two ways to get a token.

1. A person lets your app act for them: the authorization code flow with PKCE (S256). Register your client at pfos-ID, by dynamic client registration (`POST https://id.pfos.school/oauth2/register`, RFC 7591) or with a client ID metadata document (your `client_id` is the https URL of a JSON document that describes your client). Send the person to `https://id.pfos.school/oauth2/authorize` with `response_type=code`, your `client_id` and `redirect_uri`, `code_challenge` and `code_challenge_method=S256`, `scope=links:write` (or `links:read`, or both) and `resource=https://s.pfos.school`. They sign in and approve; exchange the code at `https://id.pfos.school/oauth2/token` with the same `resource` and your `code_verifier`. The token acts for that person.
2. An agent with its own pfos-ID agent ID: follow https://id.pfos.school/auth.md to register it (a person approves the agent and becomes its owner), then ask `https://id.pfos.school/oauth2/token` for a token as that file says, with `resource=https://s.pfos.school` and the scopes above. Agents' tokens are always bound to the agent's key (DPoP, RFC 9449). A token of an agent acting as itself acts for the agent's own account (its own history); a token of an agent acting for its owner acts for the owner.

Send the token with every request:

- A token that is not DPoP-bound (`token_type` `Bearer`): `Authorization: Bearer <access_token>`
- A DPoP-bound token (`token_type` `DPoP`, every agent's token): `Authorization: DPoP <access_token>`, and a new `DPoP: <proof>` header for every request. The proof is a JWT signed with the key the token is bound to: header `typ` `dpop+jwt`, `alg` `ES256` or `EdDSA`, your public `jwk` (never the private key); claims `jti` (new every time; a proof works once), `htm` (the HTTP method), `htu` (`https://s.pfos.school` and the path, without the query), `iat` (now; proofs older than 5 minutes are refused) and `ath` (the base64url SHA-256 of the access token).

### Personal API tokens

A person signed in on https://s.pfos.school can make a personal API token on the home page ("For developers", "API token", "New token"). It starts with `spfos_`, is shown once, never expires, and is revoked on the same page. If the user gives you theirs, send `Authorization: Bearer spfos_...`. It acts for that person on the public endpoints, `/api/v1/me`, `/api/v1/me/links`, the MCP server and the A2A agent, with no scopes to ask for. It is a secret: never put it in a URL, a link or a file others can read.

### Not for agents: the API key

`/api/v1/links` (custom codes, expiry dates, listing and deleting every link) takes only the administrator's API key. Agents cannot get one, and pfos-ID tokens do not open these endpoints.

## Errors

- `401` with `WWW-Authenticate: Bearer error="invalid_token", ...` (or `DPoP error="invalid_dpop_proof", ...`): the token was refused: expired, for another `aud` or `iss`, sent with the wrong scheme, or with a bad or reused DPoP proof. Get a new token or make a new proof.
- `401` without `error`: the endpoint needs an identity and the request had none.
- `403` with `error="insufficient_scope", scope="..."`: get a token with that scope.
- Every challenge names the metadata: `resource_metadata="https://s.pfos.school/.well-known/oauth-protected-resource"`. On the MCP server and the A2A agent the body is a JSON-RPC error; elsewhere it is `{"error": "..."}`.

## Links

- Protected resource metadata: https://s.pfos.school/.well-known/oauth-protected-resource (the QR code designer's: https://s.pfos.school/.well-known/oauth-protected-resource/qr)
- pfos-ID: https://id.pfos.school, its metadata https://id.pfos.school/.well-known/oauth-authorization-server and its own auth.md https://id.pfos.school/auth.md (agent registration)
- API and MCP reference: https://s.pfos.school/docs.md
- OpenAPI: https://s.pfos.school/openapi.json
- MCP Server Card: https://s.pfos.school/mcp/server-card
- A2A Agent Card: https://s.pfos.school/.well-known/agent-card.json
- Overview: https://s.pfos.school/llms.txt
