# Account management

Use these endpoints to manage the signed-in consumer account: profile, password,
email addresses, sign-in methods, preferences, and account activity.

## Two-factor authentication

Use the [two-factor authentication guide](https://m7.org/docs/api/api.user.m7.org/two-factor-authentication.md) for
the consumer-only `/account/me/two_factor/*` routes. It covers enrollment,
independent password, email, Device Code and account/session checks,
one-proof batch settings changes, recovery codes,
and TOTP, recovery-code, or linked-account unlink. The
[M7 settings page](https://user.m7.org/members/settings/2fa) provides the browser
workflow. The [email sign-in policy](https://m7.org/docs/api/api.user.m7.org/two-factor-authentication.md#email-sign-in-policy)
controls whether both magic-link and email-code login require a second factor.

## Authentication

Send a consumer-user access token with every request:

```http
Authorization: Bearer <ACCESS_TOKEN>
```

Account routes always operate on the signed-in user; callers cannot select a
different user ID. If the session is DPoP- or fingerprint-bound, include the
companion headers from the [authorization guide](https://m7.org/docs/api/api.user.m7.org/authorization.md).

## Authorized apps

These account-only routes manage saved OAuth consent. They require POST and a
consumer-user token. Machine credentials and principal selectors such as `uid`,
`tenant`, or `org` are rejected.

| Route | Body | Required scope |
| --- | --- | --- |
| `/account/me/authorized-apps/list` | `{}` | `account.me.authorized_apps.list` |
| `/account/me/authorized-apps/view` | `{"application_id":"APPLICATION_UUID"}` | `account.me.authorized_apps.view` |
| `/account/me/authorized-apps/revoke` | `{"application_id":"APPLICATION_UUID"}` | `account.me.authorized_apps.revoke` |

The [Authorized Apps page](https://user.m7.org/members/settings/authorized-applications)
lists one row per app with active consent. The list response uses the normal
`status`, `comment`, and `data` envelope; `data.items` contains `application_id`
(the internal registration UUID), public `client_id`, `name`,
`last_consented_at` (UTC), `grant_count`, `scopes`, and `audiences`.
Permission arrays in this list are display summaries across saved approvals;
authorization still requires one approval covering the complete request.

View returns the same app fields plus `grants`, with each approval's `id`,
`consented_at`, `scopes`, `audiences`, and `flow` (`browser`, `browser_direct`,
`device`, or null). It returns 404 when the caller has no active consent for
that app. Registration ownership does not allow viewing other users' grants.
Unavailable registrations use the name and public client ID saved at consent.

Revoke returns `data.application_id` and `data.revoked_count`. It marks every
active approval for that user/app revoked and preserves history. Repeating the
request succeeds with zero newly revoked approvals. The app must request consent
again on subsequent authorization. Existing access tokens, refresh tokens, and
sessions remain valid; an unredeemed device approval referencing a revoked grant
cannot complete its initial token pickup.

## Profile

| Route | Required fields | What it does |
| --- | --- | --- |
| `/account/me/get` | None | Returns the current profile. |
| `/account/me/set` | None | Creates or partially updates the current profile. Omitted fields are unchanged. |
| `/account/me/password` | `new`, `confirm`, `auth.pass` | Changes the account password and revokes related sessions. |

`/account/me/set` accepts only these optional profile fields:

| Field | Description |
| --- | --- |
| `display_name` | Display name. |
| `avatar` | Avatar URL or application-supported avatar value. |
| `bio` | Profile biography. |
| `locale` | Preferred locale. |
| `timezone` | Preferred time zone. |
| `pronouns` | Pronouns. |
| `website` | Website URL. |
| `social` | Social-profile data. |
| `settings` | Application-specific profile settings. |

An account without a profile is a successful read; it returns the comment
`no profile found. ready for input` instead of an error.

### Update a profile

```bash
curl -sS https://api.user.m7.org/api/v2/account/me/set \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "display_name": "Alice Example",
    "bio": "Working on M7 integrations",
    "locale": "en-US",
    "timezone": "UTC"
  }'
```

```json
{
  "status": 1,
  "comment": "OK",
  "data": {
    "display_name": "Alice Example",
    "bio": "Working on M7 integrations",
    "locale": "en-US",
    "timezone": "UTC"
  }
}
```

### Change a password

Use `auth.pass` for the current password. The API also accepts
`current_password`, `current`, `pass`, and `password`; use `auth.pass` in new
integrations.

```bash
curl -sS https://api.user.m7.org/api/v2/account/me/password \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "auth": { "pass": "CURRENT_PASSWORD" },
    "new": "NEW_PASSWORD",
    "confirm": "NEW_PASSWORD"
  }'
```

Success returns `comment: "CHANGED"`. `new` and `confirm` must match.

## Email addresses

Email routes are limited to email records owned by the signed-in user. Where a
route accepts an email lookup, send either the record `id` or the address in
`email`.

| Route | Required fields | Notes |
| --- | --- | --- |
| `/account/me/email/list` | None | Lists the user's email records. |
| `/account/me/email/get` | `id` or `email` optional | Omit both for current primary-oriented detail. |
| `/account/me/email/add` | `email` | Optional `primary`. Starts confirmation unless already verified. |
| `/account/me/email/setPrimary` | `id` or `email` | The selected email must be verified. |
| `/account/me/email/delete` | `id` or `email` | The last active email cannot be deleted. |
| `/account/me/email/confirm/send` | `id` or `email` | Starts a confirmation request. |
| `/account/me/email/confirm/resend` | `id` or `email`, `confirmation_id` | `job_id` and `job` are aliases for `confirmation_id`. |
| `/account/me/email/confirm/consume` | `id` or `email`, `confirmation_id`, `code` | `secret` is an accepted alias for `code`. |

The `add`, `confirm/send`, `confirm/resend`, and `confirm/consume` responses
place confirmation details in `data.email_confirmation`.

### Request a confirmation

```bash
curl -sS https://api.user.m7.org/api/v2/account/me/email/confirm/send \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{ "id": "EMAIL_RECORD_UUID" }'
```

```json
{
  "status": 1,
  "comment": "CONFIRMATION REQUESTED",
  "data": {
    "email_confirmation": {
      "confirmation_id": "CONFIRMATION_UUID"
    }
  }
}
```

Other successful confirmation comments are `EMAIL ALREADY VERIFIED`,
`CONFIRMATION RESENT`, and `EMAIL VERIFIED`. Setting the existing primary
returns `EMAIL ALREADY PRIMARY`; changing it returns `PRIMARY EMAIL UPDATED`.
`CONFIRMATION REQUESTED` is returned only after API Post creates and activates
the confirmation job. Token issuance or Post job failures return status `0`,
and service access tokens are never included in this response.

## Sign-in methods

These routes start hosted browser flows or return the account's available
sign-in methods. A successful start response includes `data.redirect_url`; open
that URL in the browser to continue the flow.

| Route | Required fields | Important response fields |
| --- | --- | --- |
| `/account/me/account-binding/start` | None | `success`, `redirect_url` |
| `/account/me/delegated-login/bind/start` | None | `success`, `redirect_url` |
| `/account/me/delegated-login/unlink/start` | None | `success`, `redirect_url` |
| `/account/me/federated-identities/list` | None | `success`, `delegated`, `identities` |
| `/account/me/federated-identities/unlink/start` | `identity_id` | `success`, `redirect_url` |

`data.delegated` reports the M7 username-and-password sign-in option with
`username`, `bound`, `verified`, `unlink_available`, and, when removal is
blocked, `unlink_unavailable_reason`.

Each item in `data.identities` can include `identity_id`, `vendor`,
`provider_name`, `handle`, `emails`, and `unlink_available`.

### Start account binding

```bash
curl -sS https://api.user.m7.org/api/v2/account/me/account-binding/start \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

```json
{
  "status": 1,
  "comment": "OK",
  "data": {
    "success": true,
    "redirect_url": "https://sso.user.m7.org/..."
  }
}
```

## Preferences

| Route | Required fields | Response |
| --- | --- | --- |
| `/account/preferences/get` | None | Stored preference map; success comment `GET`. |
| `/account/preferences/set` | At least one supported preference | Updated preference map; success comment `SET`. |

The supported preference keys are dotted JSON keys:

| Field | Type |
| --- | --- |
| `display.dark_mode` | Boolean |
| `display.developer_mode` | Boolean |

### Set preferences

```bash
curl -sS https://api.user.m7.org/api/v2/account/preferences/set \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "display.dark_mode": true,
    "display.developer_mode": false
  }'
```

```json
{
  "status": 1,
  "comment": "SET",
  "data": {
    "display.dark_mode": true,
    "display.developer_mode": false
  }
}
```

## Account activity

These routes return activity owned by the signed-in user.

| Route | Required fields | Optional fields | Notes |
| --- | --- | --- | --- |
| `/account/me/session/search` | None | `id`, `status`, pagination | Root SSO login records; defaults to `scope: "user"` and `status: "active"`. The caller cannot change the user or scope. |
| `/account/me/session/view` | `id` | None | `id` is the 64-character session identifier. Returns lifecycle fields and decoded `public_data`. |
| `/account/me/session/revoke` | `id` | None | Closes an eligible owned root login, revokes its token family and sends back-channel logout; response distinguishes completed and pending work. |
| `/account/me/auth/request_log/search` | None | Pagination, `client_id`, `tenant_id`, `request_kind`, `outcome`, `error_code`, `remote_ip` | Searches the caller's authentication-request history. |
| `/account/me/auth/request_log/view` | `id` | None | Returns one owned authentication-request record. |

Use the shared [pagination contract](https://m7.org/docs/api/api.user.m7.org/README.md#pagination) for searches.

For session types, lifecycle filters, root-family effects, response examples and
receiver limits, see [account sessions](https://m7.org/docs/api/api.user.m7.org/sessions.md). The encrypted payload is
not returned; public termination reasons can be displayed to the affected user.
