# Passkey (WebAuthn) Server API

> Add passkeys to any backend: create WebAuthn registration and login options, verify attestations and assertions; your app only stores the credential.

- Endpoint: `POST https://apibox.io.vn/v1/webauthn/{operation}`
- Category: Security & Crypto
- HTML docs: https://apibox.io.vn/docs/webauthn/ (Vietnamese: https://apibox.io.vn/vi/docs/webauthn/)
- Online tool: https://apibox.io.vn/tools/webauthn/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

A stateless passkey server built on SimpleWebAuthn. `POST /v1/webauthn/register/options` with `rp_id` (your domain) and `user_name` returns the `options` for `navigator.credentials.create()` (or `startRegistration()` of @simplewebauthn/browser), the `challenge` and a `challenge_token`: an HMAC-signed token that carries the challenge, the RP ID and a 5-minute expiry (`timeout_ms`, up to 10 minutes), so you do not need a session store. Then `POST /register/verify` with the browser `response`, the `challenge_token` (or your own stored `expected_challenge` + `rp_id`) and `expected_origin`: attestation formats none, packed, TPM, Android Key / SafetyNet, Apple and FIDO U2F are checked and you get `credential.id`, `credential.public_key` (COSE, base64url, plus JWK and PEM), `counter`, `transports`, the AAGUID with a provider name for well-known passkey managers, `user_verified`, `device_type` and `backed_up`.

To sign in, `POST /login/options` (optionally with `allow_credentials`) and `POST /login/verify` with the `response`, the token and the stored `credential` `{id, public_key, counter}`: the signature, origin, RP ID hash, user presence / verification (`require_user_verification`) and the signature counter are verified; save `new_counter`. Algorithms: EdDSA, ES256/384/512, RS256 and PS256 by default `[-8, -7, -257]`.

Nothing is stored on our side: you keep the credentials (one user can have several) and you decide what a successful verification means. Tokens are stateless and valid until they expire: mark them as used if you need strict one-time challenges. The FIDO Metadata Service is not included (its terms forbid redistribution), so authenticator models are not certified-checked.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `operation` | path | string | yes |  | `register/options`, `register/verify`, `login/options` or `login/verify` (or send `op` in the body). |
| `rp_id` | body | string | yes |  | Relying party ID: your domain without scheme (options; verify when using expected_challenge). |
| `rp_name` | body | string | no |  | Name shown by the browser (register/options). |
| `user_name` | body | string | yes |  | Account name, e.g. an e-mail (register/options). |
| `user_id` | body | string | no |  | Opaque user id, max 64 bytes (random when omitted; returned base64url). |
| `user_display_name` | body | string | no |  | Display name (register/options). |
| `attestation` | body | string | no | `none` | `none`, `direct` or `enterprise`. |
| `authenticator_attachment` | body | string | no |  | `platform` (device passkey) or `cross-platform` (security key). |
| `resident_key` | body | string | no | `preferred` | `required`, `preferred` or `discouraged` (discoverable credential). |
| `user_verification` | body | string | no | `preferred` | `required`, `preferred` or `discouraged`. |
| `exclude_credentials` | body | array | no |  | Credential ids (or {id, transports}) the user already has (register/options). |
| `allow_credentials` | body | array | no |  | Credentials allowed to sign in (login/options); empty = discoverable passkeys. |
| `timeout_ms` | body | number | no | `300000` | Ceremony timeout and token lifetime, 30 000-600 000 ms. |
| `response` | body | object | yes |  | The credential JSON from the browser (verify). |
| `challenge_token` | body | string | no |  | Token from the options call (verify). |
| `expected_challenge` | body | string | no |  | Your stored challenge instead of the token (verify, with rp_id). |
| `expected_origin` | body | string | no |  | Allowed origin(s), e.g. https://example.com (default https://<rp_id>). |
| `credential` | body | object | no |  | Stored credential {id, public_key, counter, transports} (login/verify). |
| `require_user_verification` | body | boolean | no | `false` | Fail when the authenticator did not verify the user (PIN / biometrics). |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/webauthn/register/options" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"rp_id":"example.com","rp_name":"Example","user_name":"an@example.vn","user_id":"user-42"}'
```

## Example response

```json
{
  "options": {
    "challenge": "Wbjgnz1u4oqN_OSWuvCfxO0QJ_E08LK0EM5t58J69w0",
    "rp": {
      "name": "Example",
      "id": "example.com"
    },
    "user": {
      "id": "dXNlci00Mg",
      "name": "an@example.vn",
      "displayName": "an@example.vn"
    },
    "pubKeyCredParams": [
      {
        "alg": -8,
        "type": "public-key"
      },
      {
        "alg": -7,
        "type": "public-key"
      },
      {
        "alg": -257,
        "type": "public-key"
      }
    ],
    "timeout": 300000,
    "attestation": "none",
    "excludeCredentials": [],
    "authenticatorSelection": {
      "residentKey": "preferred",
      "userVerification": "preferred",
      "requireResidentKey": false
    },
    "extensions": {
      "credProps": true
    },
    "hints": []
  },
  "challenge": "Wbjgnz1u4oqN_OSWuvCfxO0QJ_E08LK0EM5t58J69w0",
  "challenge_token": "eyJrIjoicmVnIiwiYyI6IldiamduejF1NG9xTl9PU1d1dkNmeE8wUUpfRTA4TEswRU01dDU4SjY5dzAiLCJyIjoiZXhhbXBsZS5jb20iLCJlIjoxNzk0Mzk0MzYyLCJvIjoiZGVtbyJ9.tT-u26UHsnaeEQj8K_fcWoIEi20XctaQPWXjveP0q7k",
  "expires_at": "2026-11-11T10:52:42.000Z",
  "user_id": "dXNlci00Mg",
  "next": "Pass `options` to navigator.credentials.create() (or startRegistration() of @simplewebauthn/browser), then POST the result as `response` with `challenge_token` to /v1/webauthn/register/verify."
}
```

## Use cases

- Add passkey login to a PHP, WordPress, Laravel or Apps Script backend without a WebAuthn library
- Replace SMS OTP with phishing-resistant passkeys for customer accounts
- Offer passwordless sign-in in internal tools and admin panels
- Prototype WebAuthn flows and inspect real authenticator responses

## FAQ

### What does my app have to store?

The credential id, public key, counter and transports of each passkey, linked to the user. Optionally the challenge (instead of the challenge_token) and used tokens.

### Does it work with iPhone, Android and Windows Hello passkeys?

Yes. Synced passkeys usually use attestation "none" and keep the counter at 0, which is accepted.

### Which origin should I send?

The exact origin of the page that called WebAuthn, e.g. https://example.com (several allowed). The rp_id must be that domain or a parent domain.
