# Identity assertion grant

> A client turns a trusted partner's signed statement about a user into a token here, for a user you have linked to that partner's account.

Your users sign in at a partner's identity provider: a workforce provider, or a parent company. With this grant, that
provider can give a client a signed statement about a user, addressed to your realm, and the client trades it here for
an access token about the **same user in your realm**, without them signing in again.

Use it for enterprise apps and MCP clients whose users already signed in at your workforce provider. The realm trusts
a partner only if you list it as a **trusted issuer**, and finds the user only through a **link** you made between the
partner's account and the user here. The reverse direction, where the realm vouches for its own users to a partner, is
[issuing identity assertions](../identity-assertion-issuing/).

## Before you begin

- **Who can do it:** a realm administrator (a group holding `RealmOwner`) trusts the partner and links its users;
  `RealmViewer` can read both. The client then redeems assertions itself.
- **Where:** today this is done through the API ([Call the API](/develop/api/) shows how to get
  `$CVYUH_SESSION`).
- **First:** the partner's issuer name and its keys (inline or at a public `https` address), and its id for each of
  your users.

## How it works

An **identity assertion** is a short-lived signed token (a JWT) that says "this is user X at our side". The realm
never matches it on email or any other shared detail, because an email can be reassigned at the partner. It matches
only on a **foreign identity link**: the partner's identifier for the user, tied to one user here.

**1. You list the partner and link the user.** The partner is an `oauth2TrustedIssuer`:

```json
{ "issuer": "https://idp.partner.example/", "jwksUri": "https://idp.partner.example/jwks",
  "status": "active", "accepts": ["idJag"] }
```

Each user who arrives from it has a `foreignIdentity`. The `link` is the partner's issuer, a space, and the partner's
`sub` for the user. `personId` is the user's id here:

```json
{ "link": "https://idp.partner.example/ fay-at-idp",
  "personId": "6f1c2a9e-3b4d-4e8f-9a01-7c2d5e6f8a90",
  "person": [{ "id": "6f1c2a9e-3b4d-4e8f-9a01-7c2d5e6f8a90" }] }
```

**2. The client presents the assertion** at the token endpoint, authenticating as itself:

```sh
curl https://foobar.cvyuh.com/oauth2/token \
  -u 'expense-app:<secret>' \
  -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \
  -d assertion=eyJ0eXAiOiJvYXV0aC1pZC1qYWcrand0Ii… \
  -d scope=expenses:read
```

The assertion's header has `typ` `oauth-id-jag+jwt`. Its claims, as the partner signed them:

```json
{ "iss": "https://idp.partner.example/", "sub": "fay-at-idp", "aud": "https://foobar.cvyuh.com",
  "client_id": "expense-app", "jti": "9b2e41c0-…", "iat": <unix time>, "exp": <iat + 300>,
  "scope": "expenses:read expenses:write", "resource": "https://api.example.com/expenses" }
```

The answer is a normal token response, with an access token about the linked user. When the assertion names a
`resource`, that sets the token's audience. Otherwise the request's own `resource`, or the client's default audience,
does. While the grant is offered, the [discovery document](../../registration/discovery/) lists it in
`authorization_grant_profiles_supported`, so clients learn it from the metadata.

## Set it up

These steps use the admin API; [Call the API](../../../../develop/api/) shows how to get a session.

1. Add `urn:ietf:params:oauth:grant-type:jwt-bearer` to the realm's `grantTypes`
   (`PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings`) and to the client's (`https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client`).
   Read the realm's settings first with `GET` on the same address, and send back the whole list with the new value
   added: **a list you send replaces the realm's list.**
2. Create an `oauth2TrustedIssuer` object for the partner, with `accepts` including `idJag`.
3. Create a `foreignIdentity` object for each user who arrives from the partner.

| Where | Setting | What it does |
|---|---|---|
| Realm and client | `grantTypes` include `urn:ietf:params:oauth:grant-type:jwt-bearer` | Off by default |
| `oauth2TrustedIssuer` | `issuer`, `jwks` or `jwksUri`, `status`, `displayName` | A partner you trust. `issuer` is matched exactly against the assertion's `iss`. `jwksUri` is fetched over public https only |
| `oauth2TrustedIssuer` | `accepts` | What you redeem from it: `idJag`, `chaining` or both (default `["idJag"]`) |
| `foreignIdentity` | `link`, `personId`, `person` | One user's link to the partner: `link` is `"<issuer> <their id for the user>"`, `personId` the user's id; both required. The realm finds the user by `personId`. One link belongs to one user only |
| Realm | `tokenEndpointAuthSigningAlgs` | The algorithms an assertion may be signed with (default `ES256`, `RS256`) |
| Realm | `clientAssertionMaxLifetimeSecs` | How far ahead an assertion's `exp` may lie (default 300) |

## Limits and defaults

| Setting or limit | Default | Range |
|---|---|---|
| `clientAssertionMaxLifetimeSecs`: how far ahead an assertion may expire | 300 | 1 to 3,600 |
| `tokenEndpointAuthSigningAlgs` | `ES256`, `RS256` | add `PS256` |
| `accepts` on a trusted issuer | `["idJag"]` | `idJag`, `chaining` or both |
| Redemptions per assertion | one | fixed |
| What it buys | an access token, no refresh token | fixed |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| `invalid_grant` for every assertion from a partner | The issuer isn't listed, is inactive, doesn't accept `idJag`, or its `issuer` differs from the assertion's `iss` | Check the `oauth2TrustedIssuer`: exact `issuer`, `status` active, `accepts` holding `idJag` |
| `invalid_grant` for one user only | No `foreignIdentity` links the partner's id for them, or they're inactive here | Create the link with their `personId` |
| `unauthorized_client` | The client is public, an agent's, or lacks the grant | Use a confidential client with `urn:ietf:params:oauth:grant-type:jwt-bearer` |

## Audit record

Each redemption, allowed or refused, is a `TOKEN_ISSUED` record with `grantType`
`urn:ietf:params:oauth:grant-type:jwt-bearer`. An issued one names the partner in `assertionIssuer` and is under the
linked user; a refused one is under the client and names the issuer the assertion claimed (`claimedAssertionIssuer`).
Changes to trusted issuers and links are in **Audit → Config**.

## Good to know

- **The assertion's header names its type**, `oauth-id-jag+jwt`. It is signed with one of the realm's
  `tokenEndpointAuthSigningAlgs`, under a key of an active trusted issuer whose `accepts` includes `idJag`. An issuer
  that isn't listed, isn't active, or doesn't accept identity assertions is refused alike.
- **It is addressed to this realm** (`aud` is the realm's issuer, as a string or a one-element array), names the
  redeeming client in `client_id`, and is fresh: it carries a `jti` and an `exp`, and `exp` lies no further ahead
  than `clientAssertionMaxLifetimeSecs`.
- **An assertion bound to a key** (`cnf.jkt`) is redeemed only under a DPoP proof of that key.
- **Every resource it names is one this realm serves**, or the assertion is refused `invalid_grant`.
- **Scopes and resources only.** An `authorization_details` claim in the assertion isn't read, a known limit against
  the identity-assertion draft.
- **An assertion this realm made itself is refused.** It is redeemed at the partner, not here.
- **Each assertion is redeemed once.**
- **The user must still be active here**, and be found through a link whose `personId` names them.
- **Only a confidential client may redeem one**, and never an agent's client. An agent acts for a user through
  [token exchange](../token-exchange/) or [backchannel authentication](../../../agents/backchannel-authentication/),
  never by signing in as them.
- **An access token only**, never a refresh token. Its scopes lie within the assertion's `scope`, the client's and
  the realm's. With no `scope` in the request, it carries every scope in the assertion that the client and the realm
  allow. It is also held to the realm's
  [governed scopes](../../../authorization/entitlement-scopes/).
- **Every redemption is recorded.** Allowed or refused, it is on the
  [audit trail](../../../../audit-reports/audit-trail/).

## Reference

### Errors

| Error | When |
|---|---|
| `invalid_grant` | The assertion is malformed, of another type, from an issuer you don't trust for it, or doesn't verify; it isn't addressed to this realm, has expired or reaches too far ahead; it names another client; it was already redeemed; it names no linked, active user; it was made by this realm; it is bound to a key the request didn't prove; or it names a resource this realm doesn't serve |
| `invalid_request` | No `assertion` is sent, or a parameter is repeated |
| `unauthorized_client` | A public client, an agent's client, or a client without the grant |
| `invalid_scope` | A scope beyond the assertion's, the client's or the realm's |
| `invalid_target` | A resource the client may not name, or none named when the client has no default audience |

## Related

- [Accept a partner's identity](../../../guides/partners/accept-a-partner-identity/): the task, start to finish.
- [Issuing identity assertions](../identity-assertion-issuing/): the realm vouches for its users to a partner.
- [Cross-domain chaining](../cross-domain-chaining/): carry an agent's authority across, too.
