# Register an app

> Add an app, an API client or a service to your realm, choose how it signs in and what it may ask for, and change or turn it off later.

Every app that signs users in through your realm, and every service that gets tokens from it, is registered as a
**client**. The registration says how the app proves who it is, which grants it uses, where the browser may return to,
and the most it may ask for. The app then points any OAuth 2.0 or OpenID Connect library at the realm's issuer,
`https://foobar.cvyuh.com/oauth2`, with its client ID.

## Before you begin

- **Who can do it:** a realm administrator (a group holding `RealmOwner`); `RealmViewer` can see the realm's apps but
  not change them.
- **Where:** today this is done through the API ([Call the API](/develop/api/) shows how to get
  `$CVYUH_SESSION`).
- **First:** know the app's kind (below), its redirect addresses, and the API it will call.

## How it works

A client is an `oauth2Client` object in the realm, and its object id is its `client_id`. Four choices shape it:

| Choice | Field | What it decides |
|---|---|---|
| How it proves who it is | `tokenEndpointAuthMethod` | A secret, a signed key assertion, a TLS certificate, an attestation, or nothing for an app that can't keep a secret |
| How it gets tokens | `grantTypes` | A browser sign-in, its own credentials, a device code, a token exchange, and the rest |
| Where users return | `redirectUris`, `postLogoutRedirectUris` | The exact addresses the browser may come back to after sign-in and sign-out |
| The most it may have | `scopes`, `allowedResources` | The scopes it may be granted and the APIs it may get tokens for |

A client's lists take effect only where they meet the realm's: a grant the realm doesn't accept, or a scope the realm
doesn't offer, is refused even when the client names it. The realm's own lists are in
[Realm OAuth settings](../oauth-settings/).

### Which kind of app

| The app | `tokenEndpointAuthMethod` | `grantTypes` | Guide |
|---|---|---|---|
| A web app with a server | `client_secret_basic` or `private_key_jwt` | `authorization_code`, `refresh_token` | [Sign users in to a web app](../../guides/sign-in-to-apps/sign-in-web-app/) |
| A single-page app | `none` | `authorization_code`, `refresh_token` | [Sign users in to a single-page app](../../guides/sign-in-to-apps/single-page-app/) |
| A mobile or desktop app | `none` | `authorization_code`, `refresh_token` | [Sign users in to your own native app](../../guides/sign-in-to-apps/native-app-sign-in/) |
| A TV or command-line tool | `none` | `urn:ietf:params:oauth:grant-type:device_code` | [Sign in a TV or command-line tool](../../guides/sign-in-to-apps/sign-in-a-tv-or-cli/) |
| A service calling an API | `client_secret_basic` or `private_key_jwt` | `client_credentials` | [Let one service call another](../../guides/services/service-to-service/) |
| An AI agent | `private_key_jwt` | `client_credentials` | [Register an agent](../../guides/agents/register-an-agent/) |

A client with `none` is **public**: it has no secret, so it signs users in but never gets a token on its own
credentials. Client credentials, token exchange and identity assertions are refused to it. [Choose how a client proves itself](../../guides/services/choose-client-authentication/) compares the methods.

## Set it up

[Call the API](../../../develop/api/) shows how to get a session for these calls.

1. **Make sure the realm offers the app's scopes.** It offers `openid`, `profile`, `email` and `offline_access` from
   the start. To add your API's scopes, read the realm's list, then send it back with yours added; the list you send
   replaces the realm's:

   ```sh
   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 '{ "scopes": ["…existing scopes", "app:read", "app:write"] }'
   ```

2. **Register the app.** The id you choose is its client ID:

   ```sh
   curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client?id=example-app' \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{
       "status": "active",
       "clientName": "Example App",
       "tokenEndpointAuthMethod": "client_secret_basic",
       "clientSecret": "<a long random secret>",
       "grantTypes": ["authorization_code", "refresh_token"],
       "redirectUris": ["https://app.example.com/callback"],
       "postLogoutRedirectUris": ["https://app.example.com/"],
       "scopes": ["openid", "profile", "email", "offline_access", "app:read"],
       "defaultScopes": ["openid"],
       "allowedResources": ["https://app.example.com/api"],
       "defaultAudience": "https://app.example.com/api"
     }'
   ```

   The realm answers `201`. `clientName` is what the consent page shows users.

3. **Give the app its settings:** the client ID `example-app`, its secret, and the issuer
   `https://foobar.cvyuh.com/oauth2`. Most libraries read every endpoint from the
   [Discovery document](../registration/discovery/). The secret is stored hashed and never shown again, so keep a copy
   for the app.

## Manage your apps

| To | Call |
|---|---|
| List the realm's apps | `GET https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client` |
| Read one | `GET https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/example-app` |
| Change it | `PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/example-app` with the fields to change |
| Turn it off | The same `PATCH`, with `{ "status": "inactive" }` |
| Remove it | `DELETE https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/example-app` |

For example, to turn the app off:

```sh
curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/example-app \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{ "status": "inactive" }'
```

An inactive app is answered exactly as one that doesn't exist: it can't sign anyone in, and its refresh tokens are
refused. Set `status` back to `active` to restore it.

To replace a secret, send a new `clientSecret`; [Client authentication](../client-security/client-authentication/)
explains how the old one can keep working for a while so the app can move.

## Good to know

- **A list you send replaces the whole list.** To add one redirect address, read the client's `redirectUris`, add
  yours, and send them all back. The same goes for scopes, grants and origins.
- **Redirect addresses match exactly.** Each is `https`, a loopback address over `http` (`http://127.0.0.1` or
  `http://[::1]`, whose port may differ), or a private-use scheme in reverse-domain form such as
  `com.example.app:/callback`. None may carry a fragment.
- **Every token names one API.** A request that names no `resource` gets `defaultAudience`, which must be one of
  `allowedResources`. With no default, such a request is refused. See [Resource indicators](../tokens/resource-indicators/).
- **Pages may call the token endpoint from the app's own sites.** `webOrigins` starts as `["+"]`, the origins of the
  app's redirect addresses. See [Browser apps](../single-sign-on/browser-apps/).
- **A client ID can't be a UUID.** Choose a readable name such as `example-app`; an ID shaped like a UUID never
  signs in.
- **Developers can register their own apps** with a token you hand out: see
  [Dynamic registration](../registration/dynamic-registration/).

## Limits and defaults

| Setting or limit | Default | Range |
|---|---|---|
| Clients in a realm | 1,000 | those you register and those developers register together; past it, a new client is refused. Ask support to raise it |
| `status` | `active` | `active` or `inactive` |
| `grantTypes` | `["client_credentials"]` | within the realm's `grantTypes` |
| `webOrigins` | `["+"]`, the origins of the redirect addresses | exact origins |
| `refreshTokenRotation` | `reuse`; always `rotate` for a public client | `rotate` or `reuse` |
| `clientSecretExpiresAt` | none, the secret doesn't expire | any time |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| The realm shows an error page, not the sign-in: "the redirect_uri is missing or is not one the client registered" | The app sent an address that isn't exactly one of `redirectUris` | Add the exact address, scheme, host, port and path, to `redirectUris` |
| `invalid_scope` for a scope you added to the client | The realm's `scopes` doesn't offer it | Add it to the realm's list, keeping the existing values |
| `invalid_target`, or a token request refused for naming no API | No `resource` was sent and the client has no `defaultAudience` | Set `defaultAudience` to one of `allowedResources` |
| `invalid_client` for an app that worked | It was turned `inactive`, its secret expired or was replaced | Check `status` and `clientSecretExpiresAt`; send the app its new secret |
| Registering a client is refused | The realm holds its most clients | Remove clients no longer used, or ask support to raise the limit |

## Audit record

Registering, changing or removing an app is a change to an `oauth2Client` object: a `CREATED`, `PATCHED`,
`UPDATED` or `DELETED` record with what changed, before and after, secrets left out. See it in **Audit → Config**, or
in [Change history](/audit-reports/audit-trail/change-history/). Each token the app gets is a `TOKEN_ISSUED`
record.

## Reference

### Client fields

| Field | What it does |
|---|---|
| `status` (`active`) | `active` or `inactive`. Only an active client signs in |
| `clientName` | The name consent shows users |
| `tokenEndpointAuthMethod` (required) | `none`, `client_secret_basic`, `client_secret_post`, `private_key_jwt`, `self_signed_tls_client_auth` or `attest_jwt_client_auth`; any other method is refused |
| `clientSecret` | The secret, for the two secret methods. Stored hashed, never readable |
| `clientSecretExpiresAt` | When the secret stops working; absent, it doesn't expire |
| `jwks`, `jwksUri` | The client's public keys, inline or at an `https` address, for `private_key_jwt`, signed requests and certificates |
| `tokenEndpointAuthSigningAlg` | Pins the algorithm its assertions are signed with |
| `grantTypes` (`["client_credentials"]`) | The grants it may use, within the realm's |
| `scopes`, `defaultScopes` | The most it may be granted, and what it gets when it asks for none |
| `allowedResources`, `defaultAudience` | The APIs it may get tokens for, and the one used when it names none |
| `servesResources` | The APIs this client is, so it may introspect their tokens and exchange them |
| `redirectUris`, `postLogoutRedirectUris` | Where the browser may return after sign-in and sign-out |
| `webOrigins` (`["+"]`) | The sites a page may call the token, revocation, pushed-request and userinfo endpoints from |
| `backchannelLogoutUri` | Where the app is told a session it signed in through has ended |
| `consentImplied` | Skip the consent page for this app, where the realm allows it |
| `firstParty` | The realm's own app, which may sign users in with its own screens |
| `refreshTokenRotation` | `rotate` or `reuse` (the default); a public client's always rotate |
| `scopeClaims` | Per scope, the user details this app gets in place of the realm's |
| `idTokenSignedResponseAlg`, `userinfoSignedResponseAlg`, `introspectionSignedResponseAlg` | How its ID tokens, userinfo answers and introspection answers are signed |
| `requirePushedAuthorizationRequests` | Take its sign-in requests only as pushed ones |
| `requestObjectSigningAlg`, `requestObjectEncryptionAlg`, `requestObjectEncryptionEnc` | How it signs, and may encrypt, its sign-in requests |
| `dpopBoundAccessTokens` | Issue it only tokens bound to its DPoP key |
| `tlsClientCertificateBoundAccessTokens` | Bind its tokens to its TLS certificate |
| `securityProfile` | `none`, `oauth2.1` or `fapi2` |
| `statusListed` | Give its tokens a status list entry, for APIs that check tokens offline |
| `authorizationDetailsTypes` | The structured permission types it may ask for |
| `exchangesAudience` | Let it exchange a token it sees for one meant for another API |
| `issuesTxnTokens` | Let it ask for transaction tokens |
| `agent`, `assertionTrust`, `spiffeId`, `clientAttesters` | The agent it signs in as, and where its credentials are trusted from |
| `backchannelTokenDeliveryMode`, `backchannelClientNotificationEndpoint`, `deferredClientNotificationEndpoint` | How an agent learns its owner answered an approval request |

Values in brackets are the defaults. Each field's own page is linked from
[Applications](../).

## Related

- [Realm OAuth settings](../oauth-settings/): the realm's lists and lifetimes every client works within.
- [Authorization code with PKCE](../single-sign-on/authorization-code/): the browser sign-in most apps use.
- [Client credentials](../tokens/client-credentials/): tokens for a service, with no user.
- [Client authentication](../client-security/client-authentication/): how a client proves who it is.
