# Choose how ID tokens are signed

> Pick the algorithm an app's ID tokens are signed with (RS256, ES256 or PS256), and which ones the realm offers.

Each app gets its ID tokens signed with the algorithm it can check, signed with the realm's key for that algorithm and
published in the realm's key set. Use this when an app's library or policy needs a particular algorithm.

| Algorithm | When |
|---|---|
| `RS256` | The default. Every OpenID Connect library supports it |
| `ES256` | Smaller tokens and faster signing. The algorithm access tokens always use |
| `PS256` | Where RSA is required but RS256 isn't allowed, as under FAPI 2.0 |

Access tokens are always ES256, whatever you choose here.

**Before you start:**

- **Who can do it:** a realm administrator, in a group that holds `RealmOwner`
  ([Delegated administration](/platform/realms/delegated-administration/)). `RealmViewer` can read the settings but
  not change them.
- **Where:** today this is done through the API; [Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`.
- **First:** have the app's client ID.

## Set the algorithm

<Steps>

1. For PS256 only, offer it in the realm. The realm offers RS256 and ES256 by default, and always RS256, as OpenID
   Connect requires:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/keySettings/keySettings \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "algorithm": { "oauth2": { "idToken": ["RS256", "ES256", "PS256"] } } }'
   ```

2. Set the app's algorithm:

   ```sh
   curl -X PATCH 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>' \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "idTokenSignedResponseAlg": "ES256" }'
   ```

</Steps>

## Check it worked

Sign in to the app and decode the ID token's header: its `alg` is the one you set, and its `kid` is in the realm's key
set.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| The sign-in fails with no ID token | The client names an algorithm the realm doesn't offer | Offer it in `keySettings` (step 1), or pick another |
| The app rejects the ID token's signature | It checks against a cached key set, or expects another algorithm | Refresh its copy of the key set; match its expected `alg` |
| Setting `RS256` is refused | The client is held to FAPI 2.0 | Use `ES256` or `PS256` |

## Undo it

`PATCH` the client with `{ "idTokenSignedResponseAlg": null }`. Its ID tokens go back to the default: `RS256`, or `ES256` under FAPI 2.0.

## Good to know

- **No fallback.** A client that names an algorithm the realm doesn't offer gets no ID token: the sign-in fails.
- **FAPI 2.0 clients** get ES256 by default, and may not use RS256. See
  [Hold a client to FAPI 2.0](../../services/fapi2-clients/).

## Related

- [OpenID Connect sign-in](../../../applications/single-sign-on/openid-connect/): ID tokens and their claims.
- [Signing keys](../../../../platform/keys/signing-keys/): the realm's keys and key set.
- [Choose which details an app receives](../choose-user-details/): what the ID token carries.
