Skip to content
Workforce IdentityMarkdown

Let developers register their own apps

Hand a developer a token their tool registers its own client with, within the limits and pins you choose.

APIRFC 7591

Outside developers building against your realm shouldn’t need a realm administrator for every app. You mint an initial access token and give it to the developer; their tool registers its own client with the standard registration call, only within what the token allows. The client is a normal client afterwards, and records which token registered it.

Before you start:

  • Who can do it: a realm administrator (a group holding RealmOwner) turns registration on and mints tokens.
  • Where: today this is done through the API; Call the API shows how to get a session.
  • What you need: the host names the developer’s app returns to.
  1. Turn registration on in the realm. It takes all four fields:

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "registration": { "enabled": true, "defaultLifetimeSecs": 3600,
    "maxLifetimeSecs": 86400, "maxUses": 10 } }'
  2. Mint a token, pinned to what the developer’s app may be:

    Terminal window
    curl https://foobar.cvyuh.com/api/v0/am/clients/v1/registration-tokens \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{
    "lifetimeSecs": 86400,
    "uses": 3,
    "grantTypes": ["authorization_code", "refresh_token"],
    "redirectHosts": ["expenses.example.com"],
    "securityProfile": "oauth2.1"
    }'

    The answer holds the token, shown once, and its id. A token lasts an hour by default and a day at most, and registers one client by default and ten at most; the realm’s registration settings set those limits.

  3. Give the token to the developer. Their tool registers its client:

    Terminal window
    curl https://foobar.cvyuh.com/oauth2/register \
    -H "Authorization: Bearer <initial access token>" \
    -H "Content-Type: application/json" \
    -d '{ "application_type": "web", "client_name": "Expense Tracker",
    "redirect_uris": ["https://expenses.example.com/callback"],
    "token_endpoint_auth_method": "none" }'

    It receives a client id such as dcr-…. It never receives a secret: a registered client is public, or proves itself with keys it names.

  • Sign-in and refresh only. Registered clients get the sign-in and refresh grants, never an agent or a first-party role, and never have consent implied.
  • Scopes. The scopes it asks for, from the realm’s scopes, or the realm’s cimdScopes if it asks for none.
  • APIs. The realm’s cimdResources. When the realm lists exactly one, that one is the client’s default, and a token request may leave resource out. With more than one, each request names its API with resource, or is refused.
  • No self-management. The tool can register only. It can’t read, change or delete its registration afterwards; a realm administrator does that, as for any client.

Read the new client as you would any other:

Terminal window
curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>' \
-H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

A registration outside the token’s pins, with an expired or revoked token, or with none at all, is refused.

On the audit trail, minting is REGISTRATION_TOKEN_MINTED and each registration, made or refused, is CLIENT_REGISTERED, both keyed by the token’s id; the token itself is never recorded. Look for them under Audit → Authentication in the dashboard.

SymptomCauseFix
Minting is refused 404Registration isn’t on in the realmTurn it on, as in step 1, with all four fields
Minting is refused 400The lifetime or the use count asked for is past the realm’s registration limitsAsk for less, or raise the limits
The developer’s registration is refusedIts redirect host, grant types or security profile fall outside the token’s pins, or the token is used up, expired or revokedMint a token whose pins match the app

Revoke a token before it’s used up, so nothing more registers with it:

Terminal window
curl -X DELETE 'https://foobar.cvyuh.com/api/v0/am/clients/v1/registration-tokens/<id>' \
-H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

Revoking is recorded as REGISTRATION_TOKEN_REVOKED. Clients already registered stay; change or deactivate them with PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>.