# Begin WebAuthn security key registration

Generates a WebAuthn challenge and registration options to enroll a new hardware security key or passkey for 2-factor authentication. A mailbox bearer or system key acting under its credential must re-prove the current password when an active password credential exists. Account and unacted system administrators, and password-less provisioning, are exempt.

## `POST /api/v1/identities/{identityId}/webauthn/registrations`

### Path parameters

- `identityId` (string, required) — Mailbox identity ULID

### Request body (required)

`application/json`

- `rpId` (string, required, 1–253 chars) — Relying Party ID (domain hostname)
- `currentPassword` (string, 1–1024 chars) — The mailbox's current password. Required for a mailbox session (including a relayed session) when an active password exists; omitted for administrators or password-less provisioning

### Responses

**200** — WebAuthn creation options to pass to navigator.credentials.create()

`application/json` → WebauthnRegistrationOptions

- `attestation` ("none", required) — Attestation conveyance preference
- `authenticatorSelection` (object, required)
  - `residentKey` (string, required) — Resident key requirement
  - `userVerification` (string, required) — User verification requirement (preferred, required, discouraged)
- `challenge` (string, required) — Base64url-encoded one-time challenge
- `excludeCredentials` (object[], required) — Credentials to exclude to prevent duplicate enrollment
  - `id` (string, required) — Base64url-encoded credential ID
  - `type` ("public-key", required) — Credential type
  - `transports` (string[]) — Allowed authenticator transport types
- `pubKeyCredParams` (object[], required) — Supported cryptographic algorithms
  - `alg` (integer, required)
  - `type` ("public-key", required)
- `rp` (object, required)
  - `id` (string, required) — Relying party ID
  - `name` (string, required) — Relying party display name
- `timeout` (integer, required) — Ceremony timeout in milliseconds
- `user` (object, required)
  - `displayName` (string, required) — User display name
  - `id` (string, required) — Base64url-encoded identity ULID
  - `name` (string, required) — User account name

**400** — password_required: a mailbox session must re-prove its active password

`application/json` → ErrorOrValidation

**401** — unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a `WWW-Authenticate: Bearer` challenge

`application/json` → ErrorBody

**403** — invalid_password

`application/json` → ErrorBody

**404** — Mailbox not found or not accessible to this principal

`application/json` → ErrorBody

**409** — no_password_credential: the password was removed during re-proof; restart registration

`application/json` → ErrorBody

**413** — too_large: JSON request body exceeds 1 MiB or 500,000 values (object keys included), checked before parsing

`application/json` → ErrorBody

**429** — rate_limited

`application/json` → ErrorBody

**503** — temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description)

`application/json` → ErrorBody

### Example request

```bash
curl -X POST 'https://api.open.email/api/v1/identities/{identityId}/webauthn/registrations' \
  -H 'Authorization: Bearer oek_…' \
  -H 'Content-Type: application/json' \
  -d '{
    "rpId": "string"
  }'
```

## TypeScript SDK

[`openemail.securityKeys.beginRegistration`](/docs/sdks/typescript/security-keys/begin-registration)

```ts
const webauthnRegistrationOptions = await openemail.securityKeys.beginRegistration(identityId, { rpId: '…' })
```
