# BolagsAPI auth.md

BolagsAPI supports human-approved OAuth for the hosted MCP server and API keys for direct REST API integrations. Agents must not create accounts, copy credentials, or approve access without the user's knowledge.

## Discovery

- OAuth authorization server: `https://api.bolagsapi.se/.well-known/oauth-authorization-server`
- MCP protected resource: `https://mcp.bolagsapi.se/.well-known/oauth-protected-resource`
- MCP endpoint: `https://mcp.bolagsapi.se/mcp`
- REST API: `https://api.bolagsapi.se`
- OpenAPI: `https://api.bolagsapi.se/openapi.json`

## Hosted MCP: OAuth authorization code with PKCE

Use this flow when the MCP client supports remote OAuth. The user signs in to BolagsAPI and approves the connection in the browser.

1. Register a public OAuth client with `POST https://api.bolagsapi.se/oauth/register`:

   ```json
   {
     "client_name": "Your agent or MCP client",
     "redirect_uris": ["http://127.0.0.1:8765/callback"]
   }
   ```

2. Generate a PKCE verifier and an S256 challenge. Plain PKCE is supported for compatibility, but S256 is recommended.
3. Open the discovered `authorization_endpoint` with `response_type=code`, the returned `client_id`, an exact registered `redirect_uri`, `scope=mcp`, `state`, `code_challenge`, and `code_challenge_method=S256`.
4. After the user approves access, exchange the authorization code at the discovered `token_endpoint` using `grant_type=authorization_code`, `client_id`, `redirect_uri`, `code`, and `code_verifier`.
5. Send the returned token as `Authorization: Bearer TOKEN` to `https://mcp.bolagsapi.se/mcp`.

OAuth clients are public and do not receive a client secret. Client-credentials grants and unattended user registration are not supported.

## REST API keys

For direct REST integrations, the user creates and revokes API keys in the [BolagsAPI dashboard](https://bolagsapi.se/dashboard/keys). Send the key only in the authorization header:

```http
Authorization: Bearer YOUR_API_KEY
```

Never place API keys in URLs, browser-visible source code, logs, or skill files. Start with the [API documentation](https://bolagsapi.se/docs) and follow the plan limits shown in the dashboard.

## Revocation and support

Users can revoke API keys and MCP connections from the dashboard. If a credential is exposed, stop using it and ask the user to revoke it immediately. Contact `hello@bolagsapi.se` for account or security help.
