# Protect an API with a ProtectedResource

> Register an API as a ProtectedResource: allocate its audience, bound its tokens, carry user attributes in them, and let a backend update those attributes.

This guide registers an HR API with Nauthera from git and follows one token from the
sign-in to the API. At the end, only the applications that list the API get tokens for
it, each token lives at most ten minutes, it carries the signed-in employee's
department and cost center so the API authorizes without calling back, and the HR
system's sync job updates those two attributes for the next token to carry. You need a
Nauthera release with its [operator](https://www.nauthera.io/docs/v1/operator) running and `kubectl`. The main
limit: an access token keeps the attribute values it was minted with until it expires,
so the API's token lifetime is how long a change can take to reach it.

| Step | Who | Resource |
|---|---|---|
| [1. Give the team a range of identifiers](#1-give-the-team-a-range-of-identifiers) | Platform team | [`Organization`](https://www.nauthera.io/docs/v1/organization-resource) `spec.protectedResources` |
| [2. Declare the attributes](#2-declare-the-attributes) | Platform team | `Organization` `spec.userAttributes` |
| [3. Register the API](#3-register-the-api) | API team | [`ProtectedResource`](https://www.nauthera.io/docs/v1/protected-resource-resource) |
| [4. Carry attributes in its tokens](#4-carry-attributes-in-its-tokens) | API team | `ProtectedResource` `spec.attributes` |
| [5. Let applications call it](#5-let-applications-call-it) | Application teams | [`OIDCClient`](https://www.nauthera.io/docs/v1/oidc-client) `spec.resources` |
| [6. Check tokens in the API](#6-check-tokens-in-the-api) | API team | The API's own code |
| [7. Let an application update attributes](#7-let-an-application-update-attributes) | Platform team, backend team | `Organization` `spec.attributeWriteGrants` |

## How the pieces fit

A protected resource is an API an organization's access tokens may name as their
audience (RFC 8707). Each piece is owned by the team that runs it, and none of them can
reach past what the level above allows:

```mermaid
flowchart TB
  subgraph P["Platform team · cluster-scoped"]
    O["Organization acme<br/>protectedResources: hr may use https://hr.acme.example/<br/>userAttributes: department, cost_center<br/>attributeWriteGrants: hr-sync may write both"]
  end
  subgraph H["HR team · namespace hr"]
    R["ProtectedResource hr-api<br/>identifier: https://hr.acme.example/api<br/>scopes, 10-minute tokens, attributes"]
    C1["OIDCClient hr-portal<br/>resources: [https://hr.acme.example/api]"]
    C2["OIDCClient hr-sync<br/>client_credentials"]
  end
  O -->|allocates the prefix| R
  O -->|declares the attributes it may select| R
  R -->|names it in aud| T(["Access token"])
  C1 -->|asks for a token for it| T
  T --> API["HR API"]
  C2 -->|"writes department, cost_center"| N["Nauthera's<br/>service attribute API"]
```

- **The platform team** decides which namespaces may register which identifiers, which
  attributes exist, and which applications may write them. One team cannot take another
  team's audience, raise its tokens' lifetime or invent an attribute.
- **The API team** registers its API: the identifier, the scopes it defines, how long its
  tokens live, which declared attributes they carry, and the client it introspects as.
- **Each application team** lists, on its `OIDCClient`, the APIs its application calls.
  Once an organization registers one protected resource, a client gets tokens only for
  registered APIs it lists.

```mermaid
sequenceDiagram
  autonumber
  actor E as Employee
  participant W as HR portal (hr-portal)
  participant N as Nauthera
  participant A as HR API
  E->>W: Opens the portal
  W->>N: /authorize scope=openid hr hr.employees:read<br/>resource=https://hr.acme.example/api
  N->>E: Sign-in, then consent
  E->>N: Signs in and agrees
  N->>W: Authorization code
  W->>N: /token with the code and the resource
  Note over N: Registered API? Listed by hr-portal?<br/>Reads the declaration and the employee's values
  N->>W: Access token: aud is the API, lives at most 10 min,<br/>carries department and cost_center
  W->>A: GET /employees/me, Authorization: Bearer token
  Note over A: Checks iss, typ, aud, exp and scope,<br/>then authorizes on department
  A->>W: 200
```

## Use cases

| You want | What to set |
|---|---|
| An internal API only certain services may call | A `ProtectedResource` with a short `accessTokenTtlSeconds`, and `spec.resources` on exactly those services' `OIDCClient`s, each using `client_credentials` |
| An API that authorizes on who the user is (their department, region, plan or tier) without calling UserInfo on every request | Attributes declared with `accessToken: true` and selected in the resource's `spec.attributes` ([step 4](#4-carry-attributes-in-its-tokens)) |
| Several teams sharing one cluster and one issuer | One `spec.protectedResources` entry per team namespace with that team's prefix ([step 1](#1-give-the-team-a-range-of-identifiers)), so no team can register an audience another team's API trusts |
| An API that must notice a revoked grant before its tokens expire | `spec.introspectionClient`, and the API introspects each token ([step 6](#6-check-tokens-in-the-api)) |
| One token for two APIs | The client lists both and names both in `resource`: the token's `aud` names each, it lives as long as the shorter-lived allows, and it carries only the attributes both select |
| A backend that owns an attribute, such as a subscription plan, loyalty tier or cost center | `applicationWrite: true` on the attribute, a grant for the backend's client, and the service attribute API ([step 7](#7-let-an-application-update-attributes)) |
| A remote MCP server | [Protect an MCP server](https://www.nauthera.io/docs/v1/guides/mcp-server): the same resource, plus the metadata MCP clients discover it by |

## 1. Give the team a range of identifiers

An organization accepts a `ProtectedResource` only under an identifier that starts with a
prefix it gives the resource's namespace. This lets the `hr` namespace register any API
under `https://hr.acme.example/`:

```yaml
apiVersion: nauthera.io/v1alpha1
kind: Organization
metadata:
  name: acme
spec:
  slug: acme
  displayName: Acme
  namespaces: [hr]
  protectedResources:
    - namespaces: [hr]
      identifierPrefixes: ["https://hr.acme.example/"]
```

A prefix is `https://` with a host, ending in `/`, or `urn:` ending in `:`.
`https://hr.acme.example/` covers `https://hr.acme.example/api` and not
`https://hr.acme.example.evil/`. In the main organization, the same entry goes in the
server's configuration, as `orgs.main.protected_resources` with `identifier_prefixes`.
An organization that allocates nothing accepts no `ProtectedResource`; see
[Allocating identifiers](https://www.nauthera.io/docs/v1/protected-resource-resource#allocating-identifiers).

## 2. Declare the attributes

The API wants each employee's department and cost center. Declare both on the
organization, add them to the `Organization` from step 1, and mark each one
`accessToken: true` so a protected resource may select it:

```yaml
apiVersion: nauthera.io/v1alpha1
kind: Organization
metadata:
  name: acme
spec:
  slug: acme
  displayName: Acme
  namespaces: [hr]
  protectedResources:
    - namespaces: [hr]
      identifierPrefixes: ["https://hr.acme.example/"]
  userAttributes:
    - name: department
      type: enum
      userAccess: read           # the employee sees it on the account page
      applicationWrite: true     # a grant may let an application write it (step 7)
      scopes: [hr]               # released only to a grant holding hr
      accessToken: true          # a ProtectedResource may select it
      labels: {en: Department, de: Abteilung}
      values:
        - {value: sales, labels: {en: Sales, de: Vertrieb}}
        - {value: engineering, labels: {en: Engineering, de: Entwicklung}}
        - {value: people, labels: {en: People, de: Personal}}
    - name: cost_center
      type: string
      maxLength: 16
      pattern: "CC-[0-9]{4}"
      userAccess: read
      applicationWrite: true
      scopes: [hr]
      accessToken: true
      labels: {en: Cost center, de: Kostenstelle}
```

Each setting decides one thing:

- **`scopes`** decides who receives the value: a client must be granted `hr`, which the
  employee consents to. The same scope releases both attributes through UserInfo.
- **`accessToken: true`** lets a protected resource select the attribute. It releases
  nothing by itself, and turning it off stops every resource's tokens carrying it from
  the next token on.
- **`userAccess: read`** shows the value on the employee's account page without letting
  them change it. `write` would let them change it; `none`, the default, hides it.
- **`maxLength`** keeps the attribute's worst case small. A resource's selection may take
  at most 4096 bytes of a token at its declared bounds, and a string counts up to six bytes
  a character up to its `maxLength` (1024 without one): select a string only with one.

The types, constraints, labels and every rule of a declaration are on
[User Attributes](https://www.nauthera.io/docs/v1/user-attributes).

## 3. Register the API

The HR team registers its API in its own namespace:

```yaml
apiVersion: nauthera.io/v1alpha1
kind: ProtectedResource
metadata:
  name: hr-api
  namespace: hr
spec:
  identifier: https://hr.acme.example/api
  displayName:
    en: HR API
    de: Personal-API
  scopes:
    - name: hr.employees:read
      descriptions:
        en: Read employee records
        de: Mitarbeiterdaten lesen
    - name: hr.employees:write
      descriptions:
        en: Change employee records
  accessTokenTtlSeconds: 600
  introspectionClient: hr-api-introspector
```

```bash
kubectl apply -f hr-api.yaml
kubectl -n hr get protectedresource hr-api   # PHASE Ready, reason Registered
```

- **`identifier`** is the `resource` a client sends and the `aud` its token names, written
  in the form the server compares: scheme and host in lower case, no default port, an
  empty path as `/`. The server refuses any other spelling as `Refused` and names the form
  to write.
- **`scopes`** are the scopes the API defines, up to 64. The dashboard's page for the API
  shows each with its description in the viewer's language.
- **`accessTokenTtlSeconds`** (30 to 86400) bounds every token for the API, whatever the
  calling client's own lifetime. It is also how long a changed attribute can lag in a
  token already issued, so keep it short for an API that authorizes on attributes.
- **`introspectionClient`** names a confidential `OIDCClient` in the same namespace, by its
  resource name, that the API introspects tokens as ([step 6](#6-check-tokens-in-the-api)).
  Leave it out if the API checks JWTs locally only.

The introspection client is an ordinary confidential client:

```yaml
apiVersion: nauthera.io/v1alpha1
kind: OIDCClient
metadata:
  name: hr-api-introspector
  namespace: hr
spec:
  clientId: hr-api-introspector
  displayName: HR API introspection
  grantTypes:
    - client_credentials
  tokenEndpointAuthMethod: client_secret_basic
  secret:
    generate: true
```

<ProductScreenshot name="dashboard-protected-resource" caption="A protected resource on the dashboard: its identifier, token lifetime, introspection client and scopes." />

## 4. Carry attributes in its tokens

Add the attributes the API reads to the resource:

```yaml
apiVersion: nauthera.io/v1alpha1
kind: ProtectedResource
metadata:
  name: hr-api
  namespace: hr
spec:
  identifier: https://hr.acme.example/api
  displayName:
    en: HR API
  scopes:
    - name: hr.employees:read
      descriptions:
        en: Read employee records
  accessTokenTtlSeconds: 600
  introspectionClient: hr-api-introspector
  attributes:
    - name: department
    - name: cost_center
```

Each entry names a declared attribute; `in: token`, the default, is the one destination.
The server refuses, on `spec.attributes[i].name`, an attribute the organization does not
declare with `accessToken: true`, and, on `spec.attributes`, a selection whose worst case
is over 4096 bytes.

A user's access token for the API then carries an attribute when all of these hold:

```mermaid
flowchart LR
  D{"Declared with<br/>accessToken: true?"} -->|yes| S{"The grant holds one<br/>of its scopes?"}
  S -->|yes| E{"Every API the token<br/>names selects it?"}
  E -->|yes| V{"The user has<br/>a value?"}
  V -->|"yes, and it conforms"| C(["Carried, under its claim"])
  V -->|"yes, but it breaks<br/>its declaration"| X(["No token:<br/>invalid_target"])
  D -->|no| N(["Left out"])
  S -->|no| N
  E -->|no| N
  V -->|no| N
```

- **The grant's scopes, not the client's.** The client registers `hr` and requests it, and
  the user consents. A client registered for `hr` that does not ask for it gets a token
  without the attributes.
- **Every audience.** A token naming two APIs carries only what both select. A token
  naming no `resource`, or an identifier the organization does not register, carries
  none, and a `client_credentials` token has no user and so no attributes.
- **No partial tokens.** A selected value that breaks its declaration, or values that
  encode past 4096 bytes, refuse that user's token with `invalid_target` (causes
  `attribute_value_invalid` and `token_attributes_too_large`) rather than leave an
  attribute out. A token for an API that selects neither is still issued. See the
  [`invalid_target` runbook](https://www.nauthera.io/docs/v1/runbooks/oauth/invalid_target).
- **Fresh at every mint.** Each token, a refreshed one's included, carries the values and
  the declaration as they are when it is minted.

The token's payload, with the API's claims at the end:

```json
{
  "iss": "https://auth.example.com/orgs/acme",
  "sub": "0193f4e2-7c1a-7b3e-9d2f-5a8c1e4b6d70",
  "aud": "https://hr.acme.example/api",
  "client_id": "hr-portal",
  "scope": "openid hr hr.employees:read",
  "org": "0193f4e0-1b2c-7d4e-8f90-a1b2c3d4e5f6",
  "sid": "8kQ3vZ0hTn2dGm5c",
  "auth_time": 1795305600,
  "iat": 1795305612,
  "nbf": 1795305612,
  "exp": 1795306212,
  "jti": "0193f4e2-8d10-7f2a-b3c4-d5e6f7a8b9c0",
  "department": "engineering",
  "cost_center": "CC-4711"
}
```

The dashboard's **Token claims** page previews exactly this for a user, a client and a
resource, and names each declared attribute it leaves out, and why.

<ProductScreenshot name="dashboard-token-claims-withheld" caption="The token claims preview naming the declared attributes a token leaves out, and the reason for each." />

## 5. Let applications call it

The portal signs employees in and calls the API for them. Its `OIDCClient` lists the API in
`spec.resources`, written exactly as the resource's `spec.identifier` is, and registers
the scopes it asks for, `hr` among them:

```yaml
apiVersion: nauthera.io/v1alpha1
kind: OIDCClient
metadata:
  name: hr-portal
  namespace: hr
spec:
  clientId: hr-portal
  displayName: HR portal
  redirectUris:
    - https://portal.acme.example/callback
  grantTypes:
    - authorization_code
    - refresh_token
  responseTypes:
    - code
  scopes:
    - openid
    - hr
    - hr.employees:read
    - offline_access
  resources:
    - https://hr.acme.example/api
  tokenEndpointAuthMethod: client_secret_basic
  pkcePolicy: required_s256
  allowRefresh: true
  secret:
    generate: true
```

It asks for a token for the API with the `resource` parameter, at the authorization
endpoint and again at the token endpoint:

```bash
# The browser goes to:
https://auth.example.com/orgs/acme/authorize?client_id=hr-portal&response_type=code\
&redirect_uri=https%3A%2F%2Fportal.acme.example%2Fcallback\
&scope=openid%20hr%20hr.employees%3Aread%20offline_access\
&resource=https%3A%2F%2Fhr.acme.example%2Fapi\
&code_challenge=$CHALLENGE&code_challenge_method=S256&state=$STATE

# The portal redeems the code:
curl -s https://auth.example.com/orgs/acme/token \
  -u "hr-portal:$CLIENT_SECRET" \
  -d grant_type=authorization_code -d code="$CODE" \
  -d redirect_uri=https://portal.acme.example/callback \
  -d code_verifier="$VERIFIER" \
  -d resource=https://hr.acme.example/api
```

- **Only listed APIs.** In an organization that registers a protected resource, a
  `resource` the client does not list, or one the organization does not register, is
  refused `invalid_target` at `/authorize`, `/par`, `/device_authorization` and `/token`,
  and the token endpoint checks again at every refresh. A client listing none may name
  none, so add `spec.resources` to every client that calls a registered API before or as
  the first one is registered.
- **Any order.** A listed API need not be registered yet; a manifest may apply the client
  and the API in either order, and the server refuses a token for the API until it is.
- **A service calling the API** as itself uses `client_credentials` with the same
  `resource`, and gets a token bounded by the API's lifetime, without attributes.

## 6. Check tokens in the API

The API never talks to the token endpoint. It validates each access token locally
against the issuer's JWKS, and checks:

1. The signature, against `https://auth.example.com/orgs/acme/.well-known/jwks.json`.
2. The header's `typ` is `at+jwt`, so an ID token is refused.
3. `iss` is the organization's issuer.
4. `aud` names `https://hr.acme.example/api`.
5. `exp`, `nbf` and `iat`.
6. `scope` holds the scope the route needs, `hr.employees:read` here.
7. For DPoP-bound tokens, the proof against `cnf.jkt`.

Then it authorizes on the attributes: an employee reads only their own department's
records, a cost center decides which budget a request books against. The
[Go](https://www.nauthera.io/docs/v1/guides/go), [.NET](https://www.nauthera.io/docs/v1/guides/dotnet) and
[Spring Boot](https://www.nauthera.io/docs/v1/guides/spring-boot) guides set this validation up.

An API that must see a revoked grant before its tokens expire introspects them as its
introspection client. Introspection describes every token whose `aud` names the API, and
answers any other caller `active: false`:

```bash
curl -s https://auth.example.com/orgs/acme/introspect \
  -u "hr-api-introspector:$INTROSPECTION_SECRET" \
  -d token="$ACCESS_TOKEN"
```

{/* Attributes in an introspection answer: nauthera/nauthera-server#2023 */}
The answer says whether the token is active, with its `scope`, `client_id`, `sub`, `aud`
and `exp`; read the attributes from the token itself.

## 7. Let an application update attributes

The HR system is where a move to another department is recorded. Its sync job, `hr-sync`,
writes `department` and `cost_center` on the employee's account, and the employee's next
token for the API carries the new values. It needs no user-admin role: the organization
grants this one client these two attributes, and nothing else.

```mermaid
sequenceDiagram
  autonumber
  participant J as hr-sync job
  participant N as Nauthera
  participant W as HR portal
  participant A as HR API
  J->>N: /token grant_type=client_credentials<br/>scope=nauthera.user-attributes:write<br/>resource=issuer/v1/user-attributes
  N->>J: Access token for the attribute API alone
  J->>N: PATCH issuer/v1/user-attributes/users/sub<br/>attributes: department=people, cost_center=CC-2001
  Note over N: Reads the grant and the client now,<br/>checks each value against its declaration
  N->>J: 200 changed: cost_center, department
  W->>N: Next refresh or sign-in
  N->>W: Token with department people, cost_center CC-2001
  W->>A: Calls the API with the new token
```

### Grant the client

The attribute must be declared with `applicationWrite: true` (step 2 does), and the
organization grants the client in `spec.attributeWriteGrants`. Add the grant to the
`Organization` from step 2, keeping everything else it declares:

```yaml
apiVersion: nauthera.io/v1alpha1
kind: Organization
metadata:
  name: acme
spec:
  slug: acme
  displayName: Acme
  namespaces: [hr]
  # protectedResources and userAttributes as in step 2
  attributeWriteGrants:
    - client: {namespace: hr, name: hr-sync}
      attributes: [department, cost_center]
      allUsers: true
```

- A grant names one confidential `OIDCClient` by namespace and name, 1 to 16 attributes,
  and exactly one of `allUsers: true` or `groups`: up to 16
  [`Group`](https://www.nauthera.io/docs/v1/group-resource)s, by namespace and name, whose members it covers. A
  regional HR system can be granted only the members of its region's group.
- Only the `Organization` grants. No client can grant itself through its registration
  or dynamic registration, being released an attribute grants nothing, and a grant
  confers no read access.
- A grant holds the client registered when it is written. A client deleted and created
  again under the same `client_id` holds nothing, and the admin API reports
  `client_replaced`; remove the grant and add it again to grant the new client.
- A grant whose client or group does not resolve is not held, and the `Organization` is
  `Pending` with `AttributeGrantReferenceNotFound`; the rest of it is written all the
  same. A grant that widens what a client may write is recorded at warning on
  `organization.updated`.
- The main organization's grants are `orgs.main.attribute_write_grants` in the server's
  configuration, naming the client by `clientId` and `namespace` and groups by display
  name.

### Register the client

The client is confidential, registered for `client_credentials` and the scope
`nauthera.user-attributes:write`:

```yaml
apiVersion: nauthera.io/v1alpha1
kind: OIDCClient
metadata:
  name: hr-sync
  namespace: hr
spec:
  clientId: hr-sync
  displayName: HR system sync
  grantTypes:
    - client_credentials
  scopes:
    - nauthera.user-attributes:write
  tokenEndpointAuthMethod: client_secret_basic
  secret:
    generate: true
```

The scope opens no admin operation, and dynamic registration refuses it with the rest of
the `nauthera.` namespace, so a self-registered client never holds it.

### Write

The job gets a token for the attribute API, `<issuer>/v1/user-attributes`. That exact
audience and no other is accepted, so a token for the attribute API is good for nothing
else, and no other token is good for it:

```bash
TOKEN=$(curl -s https://auth.example.com/orgs/acme/token \
  -u "hr-sync:$CLIENT_SECRET" \
  -d grant_type=client_credentials \
  -d scope=nauthera.user-attributes:write \
  -d resource=https://auth.example.com/orgs/acme/v1/user-attributes | jq -r .access_token)

curl -s -X PATCH \
  https://auth.example.com/orgs/acme/v1/user-attributes/users/0193f4e2-7c1a-7b3e-9d2f-5a8c1e4b6d70 \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"attributes": {"department": "people", "cost_center": "CC-2001"}}'
```

```json
{"changed": ["cost_center", "department"]}
```

- **The user** is named by their id, the `sub` of their tokens.
- **A merge patch** (RFC 7396): a member sets its attribute, `null` removes it, and an
  absent one is left alone. A member equal to the stored value writes nothing.
- **All or nothing.** Each value is held to its declaration, and one refused member
  refuses the whole patch with a `400` `validation_error` whose field errors name
  `attributes.<name>`: `not_allowed` for a department that is no member, `pattern` for a
  malformed cost center, `read_only` for an attribute the grant does not name.
- **No oracle.** A client with no grant, a user the grant does not cover and a user who
  does not exist are answered alike, `403`. The answer names what changed and never a
  value: writing grants no read.
- **Read on every request.** The API reads the grant and the client's registration on
  every write, so narrowing or removing the grant, making the client public, or taking
  `client_credentials` or the scope off its registration holds against a token already
  issued.
- **Audited** as `user.updated`, with the client as the actor and the changed names in
  `changed`.

### When the API sees the change

```mermaid
flowchart LR
  W["hr-sync writes<br/>department: people"] --> M{"The portal's next<br/>token for the API"}
  M -->|"refresh or new sign-in"| F(["Carries people"])
  O(["A token minted before the write"]) -->|"until it expires,<br/>at most accessTokenTtlSeconds"| S(["Still carries engineering"])
```

A token already issued is not changed. The API's `accessTokenTtlSeconds` bounds how long
an old value lives, and the next refresh carries the new one. UserInfo answers with the
new value at once.

### Other ways an attribute changes

| Who | Where | What they may change |
|---|---|---|
| The user | The account page, `/account` beneath the organization's issuer, which an application can link to | Attributes declared `userAccess: write` |
| A new user | [Sign-up](https://www.nauthera.io/docs/v1/sign-in-flows/sign-up) | Every `required` attribute declared `write`, which the form asks for |
| An administrator | The dashboard's user page, the admin API, `nauthera-cli` | Any declared attribute, held to its declaration |
| A granted application | The service attribute API, as above | The attributes its grant names, on the users it covers |

{/* An application acting for the signed-in user: nauthera/nauthera-server#2012 */}
An application acting for the signed-in user, rather than as itself, sends them to the
account page for an attribute they may change.

## When something is refused

| What you see | Why | Fix |
|---|---|---|
| The `ProtectedResource` is `Refused` on `spec.identifier`, naming the namespace | No `spec.protectedResources` entry gives the namespace a prefix of it | Allocate one ([step 1](#1-give-the-team-a-range-of-identifiers)) |
| `Refused`, naming the form to write | The identifier is not in the form tokens carry | Write it as the message says: `https://hr.acme.example` is `https://hr.acme.example/` |
| `Refused` on `spec.attributes[i].name` | The organization does not declare the attribute with `accessToken: true` | Set it on the declaration ([step 2](#2-declare-the-attributes)) |
| `Refused` on `spec.attributes` | The selection's worst case is over 4096 bytes | Give each string a `maxLength` and each list a `maxItems`, or select fewer |
| `IntrospectionClientNotFound` | The introspection client is missing, not registered yet or of another organization | Apply it in the same namespace; the API is registered without it meanwhile |
| `invalid_target`, cause `resource_not_registered` | The organization registers protected resources, and not this identifier | Register it, byte for byte as clients send it |
| `invalid_target`, cause `resource_not_entitled` | The client does not list the API in `spec.resources` | Add it |
| `invalid_target`, cause `attribute_value_invalid` | The user's value of a selected attribute breaks its declaration | Correct the value, or the declaration; the admin API lists it under `attribute_violations` |
| A token without an attribute | The grant lacks its scope, the user has no value, or another API in `aud` does not select it | Preview it on the dashboard's Token claims page, which names the reason |
| The `Organization` is `Pending` with `AttributeGrantReferenceNotFound` | A grant's client or group does not resolve | Apply the `OIDCClient` or `Group` it names |
| `401` from the attribute API | Not a client's own `client_credentials` token, or the client is no longer confidential and registered for the grant type and the scope | Request the token as in [Write](#write) |
| `403` from the attribute API | No grant covering this user, or the token lacks `nauthera.user-attributes:write` | Check the grant's `attributes` and `allUsers` or `groups` |

Every operator reason and OAuth error code has a [runbook](https://www.nauthera.io/docs/v1/runbooks).

## Related

- [ProtectedResource](https://www.nauthera.io/docs/v1/protected-resource-resource): every field and status reason
- [User Attributes](https://www.nauthera.io/docs/v1/user-attributes): declaring, releasing and writing attributes
- [Organization](https://www.nauthera.io/docs/v1/organization-resource): `spec.protectedResources`,
  `spec.userAttributes` and `spec.attributeWriteGrants`
- [OIDCClient](https://www.nauthera.io/docs/v1/oidc-client): `spec.resources`
- [Tokens & Sender Constraint](https://www.nauthera.io/docs/v1/tokens): token formats, DPoP and introspection
- [Protect an MCP server](https://www.nauthera.io/docs/v1/guides/mcp-server): a protected resource for MCP clients
