# Accept a partner's identity

> Let a client turn a trusted partner's signed statement about a user into access here, for users you've linked to their partner account.

Your users sign in at a partner's workforce identity provider, and the apps, MCP clients or agents they use there
need access in this realm for them. A client they use at the partner obtains a signed **identity assertion** about
them, addressed to this realm, and exchanges it here for an access token about the same user. They don't sign in
again, and you decide exactly which partners and which users.

**Before you start:**

- **Who can do it:** a realm administrator (a group holding `RealmOwner`).
- **Where:** today this is set through the API; [Call the API](../../../../develop/api/) shows how to get a session.
- **What you need:** the partner's issuer address, where it publishes its keys, and each user's identifier at the
  partner.

## Trust the partner

<Steps>

1. Offer the grant. Read the realm's settings with `GET https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings`, then
   send its `grantTypes` back with the grant added:

   ```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 '{ "grantTypes": ["…existing grant types",
                      "urn:ietf:params:oauth:grant-type:jwt-bearer"] }'
   ```

   Do the same on the client (`https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>`).

   <Aside type="caution" title="This list replaces the grant types">
     The `grantTypes` you send become the whole list, on the realm or the client. A grant you leave out is turned
     off, so always start from the list you read.
   </Aside>

2. Trust the partner, with its keys inline (`jwks`) or where it publishes them (`jwksUri`):

   ```sh
   curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2TrustedIssuer?id=workforce' \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{
       "issuer": "https://login.partner.example",
       "jwksUri": "https://login.partner.example/keys",
       "status": "active",
       "displayName": "Partner workforce sign-in"
     }'
   ```

3. Link each user to their partner identity. `link` is the partner's issuer and its identifier for the user,
   separated by one space. The user's id is their permanent id in the realm (a UUID), the same `sub` their own
   tokens carry, and it goes in both `person` and `personId`:

   ```sh
   curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/foreignIdentity?id=<link-name>' \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{
       "link": "https://login.partner.example 00u8a7b6c5d4",
       "person": [{ "id": "<user-id>" }],
       "personId": "<user-id>"
     }'
   ```

   A link matches exactly, letter case included. Each partner identifier links to one user.

4. Register the client with a key or a secret, as in
   [Choose how a client proves itself](../../services/choose-client-authentication/).
   A public client is refused.

</Steps>

## Check it worked

The client posts the assertion to `https://foobar.cvyuh.com/oauth2/token`, proving itself as a confidential client:

```text
grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer
&assertion=<the identity assertion>
```

It receives an access token about the linked user, and no refresh token: when the token expires, it gets a fresh
assertion from the partner. The realm refuses the assertion if:

- the partner isn't trusted, or is disabled;
- it isn't addressed to this realm, or not to this client;
- it was used before, or is out of date;
- no user here is linked to the partner's identifier for them, or that user is inactive.

Each attempt is a `TOKEN_ISSUED` record: an issued token on the user's trail, naming the partner as its assertion's
issuer; a refusal keyed by the client, with the issuer the assertion claimed and the error.

## Undo it

Set the partner's `status` to `inactive` (`PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2TrustedIssuer/workforce`) to refuse every
assertion it signs, or delete one user's `foreignIdentity` link to stop it for that user alone.

## Related

- [Identity assertion grant](../../../applications/tokens/identity-assertion-grant/): every check the realm makes.
- [Accept apps identified by a URL](../apps-identified-by-url/): third-party apps with no registration.
- [Share security signals](../../share-security-signals/): let a partner's events end access here.
