# Sign In

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

Authenticates a project-scoped end-user with email and password credentials and returns a Gate JWT plus refresh token on success. When MFA is enrolled and required by project policy, the response carries `mfa.required: true` and the access token's `mfa` claim is `"required"`; the end-user must complete an MFA challenge before the token carries full authority. Returns `K9O_INVALID_CREDENTIALS` (401) on credential mismatch; repeated failures trigger rate-limiting.

## 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 end user's email address. Case does not matter. |
| `password` | string | yes | The end user's password. |

```json
{
  "email": "jane@demo.example",
  "password": "correct-horse-battery-staple"
}
```

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | Either `session` (signed in) or `mfa` (a code is needed first), never both. |
| _one of_ | | |  |
| `data.user` | object | yes | The end user. |
| `data.user.id` | string | yes | The end user's id (`eu_...`). |
| `data.user.email` | string | yes | The end user's email address. An address given at sign-up is stored in lower case. |
| `data.user.status` | enum ("active", "locked", "deleted") | yes | The account's status. A successful response always carries `active`: a locked or deleted account cannot sign in. |
| `data.user.createdAt` | string (date-time) | yes | When the end user signed up. |
| `data.user.updatedAt` | object | yes | When the account record last changed, or null if it never has. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.user.lastSigninAt` | object | yes | When the end user last signed in with a password, or null if they never have (for example straight after sign-up). |
| _one of_ | | |  |
| _or_ | | |  |
| `data.user.roles` | array of string | yes | The end user's platform role. Always `["PROJECT_END_USER"]`. Roles you grant through end-user role grants are not listed here. |
| `data.user.groups` | array of string | yes | Always an empty array in this response. The end user's group names are carried in the access token's `groups` claim. |
| `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. |
| _or_ | | |  |
| `data.user` | object | yes | The end user. |
| `data.user.id` | string | yes | The end user's id (`eu_...`). |
| `data.user.email` | string | yes | The end user's email address. An address given at sign-up is stored in lower case. |
| `data.user.status` | enum ("active", "locked", "deleted") | yes | The account's status. A successful response always carries `active`: a locked or deleted account cannot sign in. |
| `data.user.createdAt` | string (date-time) | yes | When the end user signed up. |
| `data.user.updatedAt` | object | yes | When the account record last changed, or null if it never has. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.user.lastSigninAt` | object | yes | When the end user last signed in with a password, or null if they never have (for example straight after sign-up). |
| _one of_ | | |  |
| _or_ | | |  |
| `data.user.roles` | array of string | yes | The end user's platform role. Always `["PROJECT_END_USER"]`. Roles you grant through end-user role grants are not listed here. |
| `data.user.groups` | array of string | yes | Always an empty array in this response. The end user's group names are carried in the access token's `groups` claim. |
| `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. |
| `meta` | object | yes | Request metadata: cost, timing and the request and trace ids. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_INVALID_CREDENTIALS` | The supplied email or password is incorrect. |
| 429 | `K9O_RATE_LIMITED` | Too many wrong passwords for this account: its password sign-in is locked for a while (15 minutes, then 1 hour, then 4 hours within a day). Every attempt during the lock gets this answer, the right password too; `recommendation.retryAfterSec` says when to try again. Passkey, one-time code, magic link and password reset still work. |
| 401 | `K9O_MFA_REQUIRED` | Sign-in succeeded but an MFA challenge must be completed before a session is issued. |
| 502 | `K9O_IDP_FEDERATION_FAILED` | Federated sign-in via the configured identity provider returned an unprocessable response. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/gate/signin' \
  -H 'Content-Type: application/json' \
  -d '{
  "email": "jane@demo.example",
  "password": "correct-horse-battery-staple"
}'
```

### fetch

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

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.gate.signIn({
  email: 'jane@demo.example',
  password: 'correct-horse-battery-staple'
})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.gate.sign_in({
    "email": "jane@demo.example",
    "password": "correct-horse-battery-staple"
})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Gate.SignIn(ctx, map[string]any{"email": "jane@demo.example", "password": "correct-horse-battery-staple"})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.gate.sign_in(json!({"email": "jane@demo.example", "password": "correct-horse-battery-staple"})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.gate().signIn(Map.of("email", "jane@demo.example", "password", "correct-horse-battery-staple"))
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Gate.SignInAsync(new Dictionary<string, object> { ["email"] = "jane@demo.example", ["password"] = "correct-horse-battery-staple" })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.gate.sign_in({ email: "jane@demo.example", password: "correct-horse-battery-staple" })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->gate->sign_in(['email' => 'jane@demo.example', 'password' => 'correct-horse-battery-staple'])
```

### K9o

```swift
// let k9o = try K9o.createClient(orgSlug: "playground", projectSlug: "storefront", apiKey: "k9o_…")
let result = try await k9o.gate.signIn({
  email: "jane@demo.example",
  password: "correct-horse-battery-staple"
})
```

### core-kotlin

```kotlin
// val k9o = createClient { orgSlug = "playground"; projectSlug = "storefront"; apiKey = "k9o_…" }
val result = k9o.gate.signIn({
  email: "jane@demo.example",
  password: "correct-horse-battery-staple"
})
```

### k9o (Flutter)

```dart
// final k9o = K9o.createClient(orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…');
final result = await k9o.gate.signIn({
  email: 'jane@demo.example',
  password: 'correct-horse-battery-staple'
})
```

### @k9o/react-native

```javascript
// const k9o = createClient({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })  // RN, secure storage
const { data } = await k9o.gate.signIn({
  email: 'jane@demo.example',
  password: 'correct-horse-battery-staple'
})
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/identity-access/sign-in
