# PostPiper auth.md

## Audience and supported authentication

This guide is for AI agents and MCP clients acting on behalf of a PostPiper user. PostPiper currently supports user-authorized OAuth for MCP and user-provisioned API keys for MCP and REST access. A human must sign in and authorize access or create an API key.

PostPiper does not currently implement the WorkOS Auth.md agent identity registration protocol: ID-JAG identity assertions, verified-email assertions, anonymous identities, claim codes, claim-token exchange, and identity revocation event ingestion are unsupported. Do not send those payloads to the OAuth client registration endpoint. No `agent_auth` registration block is advertised until a compatible identity registration flow exists.

## 1. Discover the MCP resource and authorization server

- MCP endpoint and resource identifier: `https://mcp.postpiper.ai/mcp`
- Authoritative protected resource metadata: `https://mcp.postpiper.ai/.well-known/oauth-protected-resource/mcp`
- Website discovery copy: `https://www.postpiper.ai/.well-known/oauth-protected-resource`
- OAuth issuer: `https://mcp.postpiper.ai`
- Authorization server metadata: `https://mcp.postpiper.ai/.well-known/oauth-authorization-server`
- Full MCP client setup: `https://www.postpiper.ai/docs/mcp`

Fetch the canonical metadata and validate the resource identifier and issuer before starting authorization. Use the supported endpoints, grants, scopes, and authentication methods advertised by that metadata.

## 2. Register an OAuth client and obtain user authorization

If your MCP client supports OAuth, configure the MCP endpoint above and let the client handle discovery and authorization. The authorization server supports dynamic OAuth client registration at `https://mcp.postpiper.ai/oauth/register` and client ID metadata documents. OAuth client registration provisions an application client; it does not create a user account or grant access to the user's posts.

For clients implementing the flow directly:

1. Register your application's actual callback URI and client metadata using the advertised OAuth registration endpoint, or use a supported client ID metadata document. Use a maintained OAuth/MCP client library.
2. Generate PKCE using `S256` and a fresh state value. Start the authorization-code flow at the advertised authorization endpoint (`https://mcp.postpiper.ai/authorize`), with the registered client ID, exact callback URI, requested scopes, and resource identifier `https://mcp.postpiper.ai/mcp`.
3. Ask the user to complete sign-in and consent in their browser. Do not collect their password or bypass consent. User sign-in and any account setup happen through the normal PostPiper flow.
4. Validate the callback state and exchange the returned authorization code at the advertised token endpoint (`https://mcp.postpiper.ai/oauth/token`) using the same callback URI, PKCE verifier, resource identifier, and registered client authentication method.
5. Store credentials securely and use the access token only for the MCP resource. When a refresh token is issued, use the `refresh_token` grant at the advertised token endpoint and store any rotated token.

Supported resource scopes:

- `postpiper:read`: read owned connected accounts, drafts, and posts.
- `postpiper:write`: create or edit drafts and publish or schedule posts.
- `offline_access`: request offline access during OAuth authorization when needed; it is an authorization-server scope rather than an additional resource permission.

## 3. Alternative: user-provisioned API key

Ask the user to sign in at `https://www.postpiper.ai/login` and create a key at `https://www.postpiper.ai/dashboard/api-keys`. Use the scopes granted to that key. There is no public anonymous account or API-key provisioning endpoint.

The key may be used with the MCP endpoint or the REST base URL `https://api.postpiper.ai/v1`. MCP OAuth access tokens must not be sent to REST endpoints, which use API keys for external clients.

## 4. Send credentials and handle failures

Send credentials in the HTTP header:

```http
Authorization: Bearer <access-token-or-api-key>
```

Never place credentials in URL query parameters, public source code, logs, or chat messages. Send publishing or scheduling requests only when authorized by the user. Social account connection is managed at `https://www.postpiper.ai/dashboard/accounts`.

On an expired OAuth access token, use the supported refresh flow. If authorization is revoked or refresh fails, stop using the credential and request fresh user authorization. The OAuth server advertises a `revocation_endpoint` in its metadata; use that endpoint with a standards-compliant OAuth library when ending a grant. API keys can be revoked by the user in the API key dashboard. Missing scope requires a newly authorized credential, not repeated retries.

## Further documentation

- REST API: https://www.postpiper.ai/docs/api-reference
- OpenAPI: https://www.postpiper.ai/openapi.json
- API catalog: https://www.postpiper.ai/.well-known/api-catalog
- Privacy: https://www.postpiper.ai/privacy
- Terms: https://www.postpiper.ai/terms
