1. Docs
  2. API Reference
  3. Replace an Environment's custom token claims

Replace an Environment's custom token claims

PUT/api/v1/token-claims

Replaces the custom claims the Environment adds to its identity tokens with the list sent; an empty list removes them all. Each entry names the claim, its source (identity.metadata.<path>, organization.metadata.<path>, or a built-in identity or organization field) and the tokens it goes on. At most 20 entries. Every access token minted after the save carries them, Hosted Login and the Direct API alike, and the ID token those marked id; a session picks the change up at its next refresh. A value missing for the person is left out of the token. Send the Environment's version in If-Match to refuse a stale save: a mismatch answers 409 version_mismatch, and without the header the check is skipped. Emits environment.token_claims_updated with the list before and after.

Authentication

Bearer TokenAuthorization Option A

JWT access token. Never send alongside X-API-Key: a request carrying both is refused.

API KeyX-API-Key Option B

API key for management-tier access. Never send alongside an Authorization header: a request carrying both is refused.

Requires permission token_claims.manageAuthentication

Change the custom claims the Environment adds to its tokens. A scoped API key must hold it as a scope; a full-access key is unrestricted within its Environment; a developer's token needs the Console capability that covers it. A credential without it is refused with 403.

Headers

  • If-Match

    Optimistic-lock version of the resource. Send the `version` field returned on read; the server rejects with 409 if the row has changed since.

Request body

application/json

claimsTokenClaimEntryDto[] Required

The whole mapping, in the order claims are added to a token, at most 20 entries. An empty list removes every custom claim.

Responses

application/json

  • dataTokenClaimsResponseDto*

application/json

  • errorApiErrorBodyDto*

application/json

  • errorApiErrorBodyDto*

application/json

  • errorApiErrorBodyDto*

application/json

  • errorApiErrorBodyDto*

Errors

When the request can't be completed, the response body includes a stable error code you can branch on, and a correlation_id (also sent as the X-Correlation-Id header). Quote the correlation id when you contact support: it identifies the exact request in Canopy's logs. A request refused by an authorization check answers 403 with the code authorization.denied, and its data names the denial_reason and the permission checked.

403authorization.deniedForbidden
When it happens

The credential does not hold the permission this operation checks: a scoped API key without the scope, a developer without the Console capability that covers it, or a permission granted somewhere other than the node the request targets. The error's data names the permission.

Remediation

Add the permission named in the Authentication section to the key's scopes, or ask an account administrator to grant the covering capability, then retry. For a node-scoped operation, make sure the grant reaches the node you are acting on.

Returned object

Request
curl -X PUT "https://auth.canopy-io.com/api/v1/token-claims" \
  -H "If-Match: "3"" \
  -H "X-API-Key: $CANOPY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "claims": [
      {
        "claim": "plan",
        "source": "identity.metadata.plan",
        "tokens": [
          "access",
          "id"
        ]
      }
    ]
  }'
Response
{
  "data": {
    "version": 0,
    "claims": [
      {
        "claim": "plan",
        "source": "identity.metadata.plan",
        "tokens": [
          "access",
          "id"
        ]
      }
    ]
  }
}
Related endpoints
GETGet an Environment's custom token claims
Was this page helpful?

Tell us how we can improve this guide.