# Confirm TOTP

`POST /gate/mfa/totp/confirm` · Identity & Access · Sign-in & Sessions

Activates a pending TOTP MFA enrollment by verifying the first valid code from the authenticator app. On success, the `mfa_`-prefixed factor record is marked verified and MFA becomes active for the end-user's sign-in flows. An incorrect code returns an error without consuming the enrollment.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `factorId` | string | yes | The `factor.id` from the enroll response (`eumf_...`). |
| `code` | string | yes | A current code from the authenticator app just set up. |
| `currentCode` | string | no | A current code from an authenticator the end user already has confirmed. Required when adding a second or later authenticator; without it the request gets 401 `K9O_MFA_REQUIRED`. |

```json
{
  "factorId": "string",
  "code": "string"
}
```

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The confirmed authenticator, and new session tokens when the end user's sessions were ended. |
| `data.factor` | object | yes | The authenticator that was confirmed. |
| `data.factor.id` | string | yes | The authenticator's id (`eumf_...`). |
| `data.factor.verifiedAt` | string (date-time) | yes | When the authenticator was confirmed. It is asked for at every sign-in after this. |
| `data.session` | object | no | Present only when this is the end user's first confirmed authenticator. Every existing session of the end user, the caller's included, was ended because none was made with a code; use these new tokens instead. |
| `data.session.accessToken` | string | yes | A signed JWT that authenticates the end user to this project's API. Send it as `Authorization: Bearer <accessToken>`. Its subject (`sub`) is the end user's id (`eu_...`), its audience (`aud`) is the project id (`proj_...`), and its issuer is the API origin of the region that holds the end user. It lives for the project's end-user access token lifetime: 30 minutes by default, settable from 5 to 60 minutes. `expiresAt` is when it expires. It cannot be revoked early: signing out or revoking sessions stops the next refresh, but a token already issued stays valid until `expiresAt`. |
| `data.session.refreshToken` | string | yes | An opaque secret (43 base64url characters) that gets a new access token from `POST /@{projectSlug}/gate/refresh`. Store it securely and never send it anywhere else. It is single use: every refresh returns a new refresh token, and sending the one it replaced a second time ends the whole session. It stops working when the session ends: on sign-out, a password reset, a revoke-all, or when the project's session limits are reached (by default 30 days without a refresh, or 90 days after sign-in, whichever comes first). |
| `data.session.expiresAt` | string (date-time) | yes | When `accessToken` expires. Refresh before this time to keep the end user signed in. |
| `meta` | object | yes | Request metadata: cost, timing and the request and trace ids. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_SESSION_EXPIRED` | Your session has expired or been revoked. Sign in again to continue. |
| 401 | `K9O_INVALID_CREDENTIALS` | The TOTP code you entered is incorrect. Check your authenticator app and try again. |
| 404 | `K9O_END_USER_NOT_FOUND` | No account was found for the provided identity. |
| 401 | `K9O_MFA_REQUIRED` | Adding a further authenticator needs a current code from one already confirmed (currentCode). |
| 429 | `K9O_RATE_LIMITED` | Too many wrong codes for this authenticator; try again in 15 minutes. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/gate/mfa/totp/confirm' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "factorId": "string",
  "code": "string"
}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/gate/mfa/totp/confirm', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
  "factorId": "string",
  "code": "string"
}),
});
const { data, meta } = await res.json();
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.gate.mfa.totp.confirm({
  factorId: 'string',
  code: 'string'
})
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/identity-access/confirm-totp
