# Verify OTP

`POST /gate/otp/verify` · Identity & Access · Sign-in & Sessions

Verifies a one-time password previously sent to the end-user's email and, on success, issues a Gate JWT and refresh token. Returns `K9O_OTP_EXPIRED` (410) if the code is expired or already used, or `K9O_INVALID_CREDENTIALS` (401) if the code is incorrect.

## 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 |
|---|---|---|---|
| `email` | string (email) | yes | The address the code was sent to. |
| `code` | string | yes | The 6-digit code from the email. Only the latest code for this address and purpose counts; it expires after 5 minutes and dies after 5 wrong guesses. |
| `purpose` | enum ("signin", "magic_link", "password_reset", "mfa_challenge") | no | What the code is for. Default `signin`, the only purpose whose verify signs the end user in. A code is checked against requests with the same purpose only. Send the same purpose as the request. |

```json
{
  "email": "jane@demo.example",
  "code": "string",
  "purpose": "signin"
}
```

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | For purpose `signin`, either `session` or `mfa`. For any other purpose, neither. |
| _one of_ | | |  |
| `data.verified` | enum (true) | yes | Always `true`: the code was right and is now used up. |
| `data.session` | object | yes | The tokens for the new session. Keep the refresh token for `POST /@{projectSlug}/gate/refresh` and send the access token on API calls. |
| `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. |
| `data.endUserId` | string | yes | The end user the code belongs to (`eu_...`). |
| _or_ | | |  |
| `data.verified` | enum (true) | yes | Always `true`: the code was right and is now used up. |
| `data.mfa` | object | yes | Present instead of `session` when the end user has a confirmed authenticator app: the sign-in needs a code first. |
| `data.mfa.required` | enum (true) | yes | Always `true`: the end user has a confirmed authenticator app, so this sign-in needs a code before it gets a session. |
| `data.mfa.challengeId` | string | yes | An opaque, single-use id for this sign-in (43 base64url characters). Send it with a current code from the end user's authenticator app to `POST /@{projectSlug}/gate/mfa/challenge`, on the origin in `resident.origin`, to get the session. A new sign-in by the same door replaces it, and it dies after 5 wrong codes. |
| `data.mfa.expiresAt` | string (date-time) | yes | When the challenge expires, 5 minutes after it was issued. After that the end user signs in again. |
| `data.mfa.methodsAvailable` | array of enum ("totp") | yes | The second factors that can answer this challenge. Always `["totp"]`: a time-based code from an authenticator app. |
| `data.mfa.resident` | object | yes | Where the challenge lives. |
| `data.mfa.resident.region` | string | yes | The region that holds the end user and this challenge. |
| `data.mfa.resident.origin` | string | yes | That region's API origin. Send the challenge answer here: no other region has the challenge. |
| `data.endUserId` | string | yes | The end user the code belongs to (`eu_...`). |
| _or_ | | |  |
| `data.verified` | enum (true) | yes | Always `true`: the code was right and is now used up. |
| `data.endUserId` | string | no | The end user the code belongs to (`eu_...`). Absent when the address belongs to no active end user. |
| `meta` | object | yes | Request metadata: cost, timing and the request and trace ids. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_INVALID_CREDENTIALS` | The OTP code you entered does not match. Check the code and try again. |
| 404 | `K9O_END_USER_NOT_FOUND` | No account was found for the provided identity. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/gate/otp/verify' \
  -H 'Content-Type: application/json' \
  -d '{
  "email": "jane@demo.example",
  "code": "string",
  "purpose": "signin"
}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/gate/otp/verify', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
  "email": "jane@demo.example",
  "code": "string",
  "purpose": "signin"
}),
});
const { data, meta } = await res.json();
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.gate.passwordless.verifyOtp({
  email: 'jane@demo.example',
  code: 'string',
  purpose: 'signin'
})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.gate.passwordless.verify_otp({
    "email": "jane@demo.example",
    "code": "string",
    "purpose": "signin"
})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Gate.Passwordless.VerifyOtp(ctx, map[string]any{"email": "jane@demo.example", "code": "string", "purpose": "signin"})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.gate.passwordless.verify_otp(json!({"email": "jane@demo.example", "code": "string", "purpose": "signin"})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.gate().passwordless().verifyOtp(Map.of("email", "jane@demo.example", "code", "string", "purpose", "signin"))
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Gate.Passwordless.VerifyOtpAsync(new Dictionary<string, object> { ["email"] = "jane@demo.example", ["code"] = "string", ["purpose"] = "signin" })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.gate.passwordless.verify_otp({ email: "jane@demo.example", code: "string", purpose: "signin" })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->gate->passwordless->verify_otp(['email' => 'jane@demo.example', 'code' => 'string', 'purpose' => 'signin'])
```

### K9o

```swift
// let k9o = try K9o.createClient(orgSlug: "playground", projectSlug: "storefront", apiKey: "k9o_…")
let result = try await k9o.gate.passwordless.verifyOtp({
  email: "jane@demo.example",
  code: "string",
  purpose: "signin"
})
```

### core-kotlin

```kotlin
// val k9o = createClient { orgSlug = "playground"; projectSlug = "storefront"; apiKey = "k9o_…" }
val result = k9o.gate.passwordless.verifyOtp({
  email: "jane@demo.example",
  code: "string",
  purpose: "signin"
})
```

### k9o (Flutter)

```dart
// final k9o = K9o.createClient(orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…');
final result = await k9o.gate.passwordless.verifyOtp({
  email: 'jane@demo.example',
  code: 'string',
  purpose: 'signin'
})
```

### @k9o/react-native

```javascript
// const k9o = createClient({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })  // RN, secure storage
const { data } = await k9o.gate.passwordless.verifyOtp({
  email: 'jane@demo.example',
  code: 'string',
  purpose: 'signin'
})
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/identity-access/verify-otp
