# Security profiles

> One client setting holds a client to a named set of rules, OAuth 2.1 or the stricter FAPI 2.0 for high-value data.

Instead of setting a dozen options one by one, you name a **profile** for the client. The realm refuses a
registration that can never meet it, and holds the client to it on every request.

Choose `fapi2` for clients handling money, health records or anything regulated, and wherever an ecosystem asks for
FAPI 2.0. Choose `oauth2.1` when you want the client's registration to say what it relies on. An
[agent's](../../../agents/ai-agents/) client is `fapi2` unless you name another profile.

## Before you begin

- **Who can do it:** a realm administrator (a group holding `RealmOwner`); `RealmViewer` can read a client's profile
  but not change it.
- **Where:** today this is done through the API ([Call the API](/develop/api/) shows how to get
  `$CVYUH_SESSION`).
- **First:** for `fapi2`, the client holds a P-256 key for `private_key_jwt` and can sign [DPoP](../dpop/) proofs.

## How it works

| Profile | What it holds the client to |
|---|---|
| `none` (default for a user's app) | The realm's own rules, which already meet OAuth 2.1 |
| `oauth2.1` | The same. The realm already requires PKCE, exact return addresses and rotation for public apps, and has no implicit or password grant. Choose it to state that you rely on that |
| `fapi2` (default for an agent's app, unless it authenticates by [attestation](../attestation/), when `oauth2.1` is) | Everything above, plus the rules below |

A `fapi2` client is held to FAPI 2.0:

- **It authenticates with `private_key_jwt` and is DPoP-bound.** It never holds a secret, is never a public app, and
  never authenticates by [attestation](../attestation/). Every token request carries a [DPoP](../dpop/) proof, and
  every token it gets is bound to the proof's key. FAPI 2.0 also allows mutual-TLS client authentication and
  [certificate-bound tokens](../certificate-bound-tokens/); a `fapi2` client isn't offered them.
- **Sign-in requests must be [pushed](../pushed-authorization-requests/)** first.
- **No RS256, anywhere.** Every algorithm the client names is ES256 or PS256: `tokenEndpointAuthSigningAlg`,
  `idTokenSignedResponseAlg`, `userinfoSignedResponseAlg` and `requestObjectSigningAlg` alike.
- **Its assertions** may use only those of the realm's `tokenEndpointAuthSigningAlgs` that are ES256 or PS256. The
  realm's default list is `ES256` and `RS256`, so by default a `fapi2` client signs its assertions with ES256 alone.
  Add `PS256` to the realm's list for clients that sign with it.
- **Its ID tokens** are signed ES256 unless it asks for PS256, and so are its signed introspection answers.
- **Its refresh tokens are not rotated:** `refreshTokenRotation: rotate` is refused.
- **A minute at most**, both for clock tolerance on its assertions and for how long its sign-in code lives.

## Set it up

Name the profile when you register the client (see [Call the API](../../../../develop/api/)):

```sh
curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client?id=payments-app' \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "active",
    "clientName": "Payments",
    "securityProfile": "fapi2",
    "tokenEndpointAuthMethod": "private_key_jwt",
    "tokenEndpointAuthSigningAlg": "ES256",
    "jwks": { "keys": [ { "kty": "EC", "crv": "P-256", "kid": "pay-1", "x": "…", "y": "…" } ] },
    "grantTypes": ["authorization_code", "refresh_token"],
    "redirectUris": ["https://pay.example.com/callback"],
    "scopes": ["openid", "payments:initiate"]
  }'
```

You don't set `requirePushedAuthorizationRequests` or `dpopBoundAccessTokens`: the profile forces both on.

| Where | Setting | What it does |
|---|---|---|
| Client | `securityProfile` | `none`, `oauth2.1` or `fapi2`. Left out, an agent's app is written `fapi2`, or `oauth2.1` when it authenticates by attestation, and any other app is `none` |
| Realm | `tokenEndpointAuthSigningAlgs` | The algorithms any client's assertions may use (`ES256`, `RS256` by default). A `fapi2` client uses only the ES256 and PS256 among them |

## Limits and defaults

| Setting or limit | Default | Range |
|---|---|---|
| `securityProfile` | `none`; `fapi2` for an agent's client, `oauth2.1` for an attesting agent's | `none`, `oauth2.1`, `fapi2` |
| `fapi2` clock tolerance and sign-in code life | at most 60 seconds | fixed |
| `fapi2` signing algorithms | `ES256`, `PS256` | fixed |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| Saving a `fapi2` client is refused with a reason | A field the profile forbids (see Errors below) | Change the field the reason names |
| A `fapi2` app's sign-in fails at once | It sends its sign-in request through the browser, not pushed | Push it first ([Pushed authorization requests](../pushed-authorization-requests/)) |
| `invalid_dpop_proof` from a `fapi2` client | No DPoP proof on the token request | Send a proof on every token request |

## Audit record

The profile is part of the client: setting or changing it is a change in **Audit → Config**. A request refused for
breaking the profile is a `TOKEN_ISSUED` record with result `FAILED`.

## Good to know

- **An agent's app keeps a profile it names.** One that must take plain bearer tokens names `none`.
- **No EdDSA yet.** FAPI 2.0 also allows EdDSA signatures; the realm doesn't offer them. They are planned:
  [Ed25519 signing](../../../../platform/keys/whats-next/#ed25519-signing).
- **Requests are held to the profile, not only the registration.** A `fapi2` client's sign-in request that wasn't
  pushed is refused, and so is a token request without a DPoP proof (`invalid_dpop_proof`).

## Reference

### Errors

A client that can never meet `fapi2` is refused when you write it (`400`), with the reason:

| Reason | When |
|---|---|
| `a fapi2 client takes no attestation as client authentication; an attesting agent's client is oauth2.1` | `tokenEndpointAuthMethod` is `attest_jwt_client_auth` |
| `a fapi2 client authenticates with private_key_jwt only` | `tokenEndpointAuthMethod` is a secret method or `none` |
| `a fapi2 client's refresh tokens are not rotated (refreshTokenRotation: rotate)` | `refreshTokenRotation` is `rotate` |
| `a fapi2 client signs only with ES256 or PS256 (<field> is RS256)` | Any `…SigningAlg` or `…SignedResponseAlg` field names RS256 |

## Related

- [Hold a client to FAPI 2.0](../../../guides/services/fapi2-clients/): the task, start to finish.
- [DPoP](../dpop/): the token binding `fapi2` requires.
- [Pushed authorization requests](../pushed-authorization-requests/): the sign-in requests `fapi2` requires.
- [Client authentication](../client-authentication/): the methods each profile allows.
