---
title: How agents get access to theStacc
description: Discover, register, get a person's approval, exchange the code for a token, and call the theStacc API or MCP server.
canonical: https://thestacc.com/auth.md
---

# auth.md

You are an agent that wants to act in a theStacc project: read or write blogs, social posts, Google Business Profile posts, Search Console and site audit data. Access always belongs to one project and is approved by an admin of that project. theStacc supports standard OAuth 2.1 (authorization code with PKCE) and project agent keys. It does not support `agent_auth` identity types (`identity_assertion`, `id-jag`, `service_auth` or `anonymous`), so an agent cannot get credentials without a person.

## Step 1: Discover

The MCP server answers an unauthenticated request with:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.thestacc.com/.well-known/oauth-protected-resource"
```

1. Fetch the protected resource metadata (RFC 9728): `GET https://mcp.thestacc.com/.well-known/oauth-protected-resource`. It names the resource (`https://mcp.thestacc.com/mcp`), the authorization server (`https://mcp.thestacc.com`) and `scopes_supported`.
2. Fetch the authorization server metadata (RFC 8414): `GET https://mcp.thestacc.com/.well-known/oauth-authorization-server`. Use its `authorization_endpoint`, `token_endpoint` and `registration_endpoint`; do not hard-code them.

The REST API is described at https://thestacc.com/openapi.json. Each operation lists the one scope it needs.

## Step 2: Pick a method

- **OAuth 2.1 (recommended).** For MCP clients and any agent that can open a browser for a person. Grant type `authorization_code`, PKCE `S256` required, public clients only (`token_endpoint_auth_method: none`).
- **Project agent key.** For scripts and servers. A person creates a key in the theStacc app (Settings, Content, Publishing, Agent access), picks its permissions and gives it to you. It starts with `sk_agent_` and is shown once. Skip to Step 6.

Scopes (ask only for what the task needs):

| Scope | Allows |
|---|---|
| `blog:read` | Read blogs, the content plan and generation progress |
| `blog:write` | Generate, edit and schedule blogs and their images |
| `blog:publish` | Publish blogs a person has approved |
| `social:read` | Read social posts and their image versions |
| `social:write` | Create and edit social posts, captions and images |
| `social:publish` | Publish social posts a person has approved |
| `gbp:read` | Read Google Business Profile locations, posts and reviews |
| `gbp:write` | Create and edit Google Business Profile posts and review replies |
| `gbp:publish` | Publish approved Google Business Profile posts and replies |
| `seo:read` | Read Search Console, GA4, site audit and keyword data |
| `seo:write` | Start site audits |
| `keywords:write` | Add and research keywords |

## Step 3: Register

Register your client with dynamic client registration (RFC 7591) at the `registration_endpoint`:

```http
POST https://api.thestacc.com/blog/api/v1/oauth/register
Content-Type: application/json

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

The response carries your `client_id`. Redirect URIs must match exactly; `http` is allowed only for `localhost` and `127.0.0.1`.

## Step 4: Claim (a person approves)

Send the person to the `authorization_endpoint` with `response_type=code`, your `client_id`, `redirect_uri`, `state`, `code_challenge`, `code_challenge_method=S256`, the `scope` you need and `resource=https://mcp.thestacc.com/mcp`. They sign in to theStacc, pick a project they administer and confirm the permissions. They can grant fewer scopes than you asked for. Their browser then returns to your `redirect_uri` with `code`, `state` and `iss`; check that `state` and `iss` match before you continue.

## Step 5: Exchange

```http
POST https://api.thestacc.com/blog/api/v1/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=...&redirect_uri=...&client_id=...&code_verifier=...
```

Response:

```json
{ "access_token": "sk_agent_...", "token_type": "Bearer", "scope": "blog:read blog:write" }
```

The `scope` field is what the person granted. Codes are single use. There is no refresh token; the access token works until a person revokes it.

## Step 6: Use the access_token

Send it as a bearer token, never in a URL:

```http
Authorization: Bearer sk_agent_...
```

- MCP: connect to `https://mcp.thestacc.com/mcp` (Streamable HTTP).
- REST: call `https://api.thestacc.com` as described in https://thestacc.com/openapi.json. Start with `GET /blog/api/v1/blogs/agent-context`, which returns the token's project and permissions.

Publishing is gated by people: a publish call only works on content a person approved in the theStacc app.

## Errors

| Status | Body | What to do |
|---|---|---|
| 401 | `WWW-Authenticate: Bearer resource_metadata=...` | The token is missing, wrong or revoked. Start again at Step 1. |
| 403 | `{"detail": {"error_code": "missing_scope", "required_scope": "..."}}` | Ask the person to approve that scope, then repeat Steps 4 and 5. |
| 400 | `{"error": "invalid_grant", ...}` | The code expired or was already used. Repeat Step 4. |
| 400 | `{"error": "invalid_redirect_uri", ...}` | Register the exact redirect URI you use. |
| 429 | `{"error": "too_many_requests", ...}` | Wait, then retry. |

## Revocation

A person revokes a token or key in the theStacc app (Settings, Content, Publishing, Agent access). Revocation takes effect on the next request, which then returns 401. There is no revocation endpoint for agents; if you no longer need access, tell the person so they can revoke it.

Questions: hello@thestacc.com. Docs: https://thestacc.com/docs
