# Finish WebAuthn security key registration

Verifies the browser WebAuthn attestation response and stores the enrolled security key.

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

### Path parameters

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

### Request body (required)

`application/json`

- `origin` (string, required, max 1024 chars) — Origin URL of the web page where ceremony took place
- `response` (object, required)
  - `attestationObject` (string, required, max 65536 chars) — Base64url-encoded attestationObject
  - `clientDataJSON` (string, required, max 65536 chars) — Base64url-encoded clientDataJSON
  - `transports` (string[], max 8 items) — Supported authenticator transports (e.g. ['usb', 'nfc'])
- `rpId` (string, required, 1–253 chars) — Relying Party ID (domain hostname)
- `name` (string, max 128 chars) — User-chosen label for the security key (e.g. 'YubiKey 5')

### Responses

**200** — Enrolled security key details

`application/json` → WebauthnCredential

- `createdAt` (integer <int64>, required) — Enrollment timestamp in epoch seconds
- `id` (string, required) — Unique WebAuthn credential ULID
- `lastUsedAt` (integer | null, required) — Timestamp when key was last used for authentication, or null
- `name` (string | null, required) — User-assigned name for the security key or passkey
- `rpId` (string, required) — Relying party ID (hostname) the key is bound to
- `transports` (array | null, required) — Supported authenticator transports (usb, nfc, ble, internal)

**400** — validation_failed, invalid_origin, challenge_expired, webauthn_failed, or duplicate_credential

`application/json` → ErrorOrValidation

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

`application/json` → ErrorBody

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

`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

**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/credentials' \
  -H 'Authorization: Bearer oek_…' \
  -H 'Content-Type: application/json' \
  -d '{
    "origin": "string",
    "response": {
      "attestationObject": "string",
      "clientDataJSON": "string"
    },
    "rpId": "string"
  }'
```

## TypeScript SDK

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

```ts
const webauthnCredential = await openemail.securityKeys.finishRegistration(identityId, {
  rpId: '…',
  origin: '…',
  response: { clientDataJSON: '…', attestationObject: '…' },
})
```
