# Self-service

> What a signed-in user reads and manages for themselves, with no administrator involved, from their own profile to the passkeys and apps on their account.

A signed-in user doesn't need an administrator to see who the realm thinks they are, or to clean up their own
account. With their own session they read their profile and their roles, list the passkeys and authenticator apps
they hold and remove one they've lost, and see and take back the apps and agents they allowed. Each of these works
for every user of the realm, staff and customers alike, and needs no set-up.

## Before you begin

- **Privilege:** none. Each call is made with the user's own session and acts on their own account only.
- **Where:** the API, and the dashboard pages users use themselves (**AI Agents**, **Approvals**, **Authorized Apps**
  and **FIDO Devices**).
- **The user is signed in** to their own realm.

## How it works

Every call here is made with the user's own session, the one they hold after signing in, and acts on their own
account only. None of them needs a realm administrator's rights.

| What the user does | Call |
|---|---|
| Read who they are: profile, roles and session | `POST /whoami/v1` |
| List their passkeys, authenticator apps and recovery codes | `GET /devices/v1` |
| Remove a passkey or an authenticator app | `DELETE /devices/v1/{id}` |
| List the apps they allowed, and remove one | `GET /me/v1/oauth2/apps`, `DELETE /me/v1/oauth2/apps/{clientId}` |
| List the agents that may act for them, and remove one | `GET /me/v1/oauth2/agents`, `DELETE /me/v1/oauth2/agents/{agent}` |
| See and answer what an agent asks them to approve | `GET /me/v1/oauth2/approvals`, `POST /me/v1/oauth2/approvals/{id}` |

The apps are covered in [Authorized apps](../../../customer-identity/self-service/authorized-apps/); the agents and
approvals in [Let users remove agents](../../../workforce-identity/guides/agents/people-remove-agents/) and
[Backchannel authentication](../../../workforce-identity/agents/backchannel-authentication/).

### Who am I

`whoami` answers, in one call, who the session belongs to (`id`, `realm`), the user's own record (`user`, without
the password, with `webAuthnDeviceCount`, the number of passkeys they hold), their administrator `roles` in the
realm, and the session's facts: `authLevel`, `authType`, `authInstant` and `expiresInSecs`.

### Their own factors

`devices/v1` lists every factor the user holds, without its secret: each with its `id`, `kind` (`webauthn` for a
passkey, `totp` for an authenticator app, `recovery` for recovery codes), `name`, `lastUsedAt`, and whether it is
`disabled`. A passkey adds what it is (`aaguid`, `keyType`, `algorithm`, whether it is backed up); an app adds its
`algorithm`, `digits` and `period`; recovery codes add how many are `remaining`. Add `?kind=webauthn` to list one
kind.

## Set it up

There's nothing to set up. As a signed-in user, with your own session in `$CVYUH_SESSION` (see
[Call the API](../../../develop/api/)):

```sh
curl -X POST https://foobar.cvyuh.com/api/v0/am/whoami/v1 \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

List your passkeys:

```sh
curl "https://foobar.cvyuh.com/api/v0/am/devices/v1?kind=webauthn" \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

```json
{ "data": [
  { "id": "<device id>", "kind": "webauthn", "name": "<name>", "lastUsedAt": "<RFC 3339 time>",
    "disabled": false, "backupEligible": true, "backupState": true, "keyType": "<key type>", "algorithm": "<algorithm>" }
] }
```

Remove one you've lost:

```sh
curl -X DELETE https://foobar.cvyuh.com/api/v0/am/devices/v1/<device id> \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

The realm answers `204`.

## What the user sees

- A removed passkey or authenticator app stops working at once; the next sign-in asks for another factor.
- Apps that follow the user's credential changes are told of each removal (see below).

## When a call fails

| Answer | What it means | What to do |
|---|---|---|
| `401` | The session has ended | Sign in again |
| `404` | No such factor on this account, or the call was made in a realm other than the user's own | Check the id from the list; call the user's own realm |
| `400` | A `DELETE` on recovery codes, which aren't removed one at a time | Keep them; they're the way back in |

## Audit record

Each removal is recorded as `DELETED` on the factor, with the user as the one who made it, and as a credential change
sent to anyone following the user's credential changes through
[Send signals](../../../workforce-identity/signals/shared-signals/).

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| A user has lost or removed every factor and can't sign in | Recovery codes are the way back in; without them, no administrator call clears a user's factors today | The user signs in with a recovery code and adds a new factor. If they have none left, see the known limitation below |
| `whoami` answers `user: null` | The call was made in a realm below the user's own | Call the user's own realm for their record |

**When a user has no way back in.** An administrator can't yet remove another user's factors or issue new recovery
codes, and users can't rename factors or make new recovery codes themselves. Ask users to keep their recovery codes,
and to hold more than one factor. See [Known limitations](../../../reference/known-limitations/#sign-in-and-sessions).

## Good to know

- **Only in the user's own realm.** Listing or removing factors in any other realm answers `404`.
- **Recovery codes aren't removed one at a time.** They are the way back in when every other factor is gone; a
  `DELETE` on them answers `400`.
- **`whoami` reads the user's record only in their own realm.** Asked in a realm below theirs, `user` is `null`,
  while `roles` says what they may administer there.

## Related

- [Sign-in methods](../../../workforce-identity/authentication/sign-in-methods/): the factors a user holds.
- [Authorized apps](../../../customer-identity/self-service/authorized-apps/): the apps a user allowed.
- [Add and change users](../add-and-change-users/): what an administrator changes for them.
