> Documentation index: https://docs.zernio.com/llms.txt. Every page is also Markdown: add .md to its URL.

# OAuth errors

The errors the Zernio authorization server and the API return to OAuth apps, what causes each one, and how to fix it.

The OAuth endpoints answer errors in the RFC 6749 shape. The API answers its own error shape, with a `WWW-Authenticate` header for token problems.

```json
{ "error": "invalid_grant", "error_description": "Authorization code already used" }
```

## Errors on the callback

Before the user reaches the consent screen, Zernio checks the request. Once `client_id` and `redirect_uri` are valid, problems go back to your callback as `error` and `error_description` query parameters, with your `state`.

| `error` | Cause | Fix |
|---|---|---|
| `access_denied` | The user clicked **Deny** | Show a way to try again |
| `invalid_request` | No `code_challenge`, or a method other than `S256` | Send a PKCE challenge with `S256` |
| `unsupported_response_type` | `response_type` is not `code` | Send `response_type=code` |
| `invalid_scope` | Unknown scope, or one the client did not register | Register a new client with the scope, or ask for less |
| `invalid_target` | `resource` is not a Zernio resource | Leave `resource` out |

An unknown `client_id` or an unregistered `redirect_uri` is shown on the Zernio page instead, never sent to the redirect.

## Registration errors

| Status | `error` | Cause |
|---|---|---|
| 400 | `invalid_request` | The body is not JSON |
| 400 | `invalid_redirect_uri` | No redirect URIs, more than 10, or one that is not https, loopback or an app scheme |
| 400 | `invalid_client_metadata` | Missing `client_name`, unknown scope or unsupported auth method |
| 429 | `too_many_requests` | More than 5 registrations a minute from one IP address |

## Token endpoint errors

| Status | `error` | Cause | Fix |
|---|---|---|---|
| 400 | `invalid_request` | A required field is missing (for example `code_verifier is required`), or the body is not form-encoded or JSON | Send every field of the grant |
| 400 | `invalid_client` | Unknown `client_id` | Register the client again |
| 401 | `invalid_client` | Wrong or missing secret for a confidential client, or an unknown client sent with Basic auth | Check the client ID and secret |
| 400 | `invalid_grant` | Code used, expired (10 minutes) or for another client | Start the authorization again |
| 400 | `invalid_grant` | `redirect_uri` mismatch or PKCE verification failed | Send the same `redirect_uri` and the matching verifier |
| 400 | `invalid_grant` | Refresh token revoked, expired or replaced | Send the user through consent again |
| 400 | `invalid_scope` | A refresh asked for more than the grant | Ask for the same scope or less |
| 400 | `unsupported_grant_type` | Not `authorization_code` or `refresh_token` | Use one of those |

## API errors with an OAuth token

A `401` means the token no longer works: refresh once, and if that fails, ask the user to connect again.

A `403` means the token works but lacks access. Do not refresh. Ask for the scope named in `WWW-Authenticate`.

| Status | `code` | Cause | Fix |
|---|---|---|---|
| 401 | `invalid_credentials` | Token expired, revoked, or the user removed your app | Refresh. If that fails, reconnect |
| 403 | `insufficient_permissions` | The grant does not cover the endpoint | Re-authorize with the scope in `WWW-Authenticate` |
| 403 | `insufficient_permissions` | The endpoint manages API keys, invites, connected apps, members, SSO or account deletion | Not available to OAuth apps |
| 402 | `PAYMENT_REQUIRED` | The workspace has no billing set up (`reason: workspace_billing_required`), or its billing is paused | Ask the user to set up billing |
| 429 | | More than 600 requests a minute for this user, or 60 in a workspace without billing | Wait `Retry-After` seconds |

A 403 for a missing scope looks like this:

```http
HTTP/2 403
WWW-Authenticate: Bearer error="insufficient_scope", scope="posts:read posts:write accounts:read email analytics:read"
```

```json
{
  "error": "This connector token has the 'analytics' resource group disabled. GET /api/v1/analytics requires it. Reconnect the integration with 'analytics' enabled to grant it.",
  "code": "insufficient_permissions",
  "required_group": "analytics"
}
```

## Related

- [Quickstart](/oauth/quickstart)
- [Scopes](/oauth/scopes)