# insufficient_scope

The access token is valid but does not carry the scope the operation requires (RFC 6750 §3.1).

## Meaning

Sent as `403` with a `WWW-Authenticate: Bearer error="insufficient_scope", scope="..."`
challenge, never in a token-endpoint body. The `scope` parameter names what the operation
needs. Today it comes from the admin API, where the token lacks the `nauthera.` admin scope
the route's permission maps to; from dynamic registration (`/register`), where an initial
access token lacks `nauthera.clients:register`; and from the service attribute API
(`PATCH /v1/user-attributes/users/{user_id}`), where a client's token lacks
`nauthera.user-attributes:write`. The body of a registration refusal says
`access_denied`, because RFC 7591 §3.2.2 has no `insufficient_scope` code.

## Impact

The caller is authenticated but may not perform this operation with this token. It is a
configuration fault on the client's side, not an attack: the token was granted narrower than
the call needs. Nothing was read or changed.

## Diagnosis

1. Read the `scope` parameter of the response's `WWW-Authenticate` header: it is the scope
   the operation requires.
2. Decode the access token and compare its `scope` claim with that value.
3. Admin API refusals are recorded with reason `missing_scope`; registration refusals as
   `client.registration.attempted` with cause `insufficient_scope`; service attribute
   writes as `user.updated`, denied with reason `insufficient_scope`. Find either on the
   dashboard's Troubleshooting page by `X-Request-ID`.
4. Check that the client is registered for the scope (`spec.scopes` on its OIDCClient, or
   `allowed_scopes` of the registration policy) and that the token request asked for it.

## Mitigation

- As a client developer: request a token with the scope the challenge names, and register
  the client for it first if it is not.
- As an operator: add the scope to the client's registration, or, for the admin API, grant the
  caller a role whose permissions map to it.

## Escalation

If a token that carries the named scope is still refused, open an issue with the request id,
the server version and the route. Never attach the token itself.

---

[OAuth error runbooks](https://www.nauthera.io/docs/v1/runbooks/oauth) · Generated from [`internal/runbook/oauth.yaml`](https://github.com/nauthera/nauthera-server/blob/main/internal/runbook/oauth.yaml) in nauthera-server.
