# Name users by your own directory's attributes

> Tell the realm which attribute users sign in with, so sign-in, consent and tokens follow your directory.

If your users are described with attribute names of your own, for example signing in with an email address, tell the
realm through its **identity binding**. Sign-in, consent, tokens and the admin pages all read the same binding, so
they always agree.

| Field | Default | Decides |
|---|---|---|
| `namingAttr` | `uid` | The attribute users sign in with, their name where they have no `displayName`, and their name in an agent's `business_owner` claim |

The name a user is shown by is always their `displayName` attribute; the binding has no field for it. Leave the
binding's other fields as they are.

**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:** every user must have the naming attribute you choose, and its values must be unique.

## Set the binding

<Steps>

1. Set the binding the first time. Fields you leave out keep their defaults:

   ```sh
   curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/identityBinding?id=identityBinding' \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "namingAttr": "email" }'
   ```

2. To change it later:

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

</Steps>

## Check it worked

Sign in as a test user with their email address. The consent page, and the `name` detail apps receive, show the
user's `displayName`, or the naming attribute where it is empty. Tokens are unaffected: `sub` is always the user's
permanent ID, whatever they sign in with.

The change is in the realm's change history as a record on `identityBinding`, before and after: see
**Audit → Config** in the dashboard.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| Some users can't sign in after the change | They have no value in the new attribute | Give every user a value, or change back |
| Two users answer to one name | The attribute's values aren't unique | Make them unique before switching |
| Users must still type their old name | The binding wasn't saved | Read it back with `GET https://foobar.cvyuh.com/api/v0/am/objects/v1/identityBinding/identityBinding` |

## Undo it

`PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/identityBinding/identityBinding` with `{ "namingAttr": "uid" }`.

## Related

- [OpenID Connect sign-in](../../../applications/single-sign-on/openid-connect/): how the user is named in tokens.
- [Choose which details an app receives](../choose-user-details/): `email`, `given_name` and the other details.
- [Consent](../../../../customer-identity/consent/): the page that shows the user's name.
