# Authenticate User & Issue JWT Access Token

`POST /api/identity/token`

### Overview
Authenticates a user using credentials (username/email and password).

### Authentication & Headers
- **Auth**: Public (OAuth2 Password Flow)
- **Required Header**: `API-Version: 1`
- **Optional Header**: `X-Device-ID: <device-uuid>` for client binding and anomaly tracking

### Parameters & Request Body
- **`username`** *(string, required)*: The registered account email or username.
- **`password`** *(string, required)*: The account plaintext password.

### Behavior & MFA Flow
1. **Standard Flow**: If MFA is disabled for the account, returns `200 OK` with `access_token` (JWT) and `refresh_token`.
2. **MFA Flow**: If Multi-Factor Authentication is enabled, returns `401 Unauthorized` with `{"detail": {"mfa": true, "mfa_token": "...", "mfa_methods": [...]}}`. Proceed to `/api/identity/mfa/send` and `/api/identity/mfa/verify`.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `X-Device-ID` | header | string | no | Unique client hardware or browser fingerprint UUID for device binding and audit security. |

## Request body

Content type: `application/x-www-form-urlencoded`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `grant_type` | string \| null | no |  |
| `username` | string | yes |  |
| `password` | string (password) | yes |  |
| `scope` | string | no |  |
| `client_id` | string \| null | no |  |
| `client_secret` | string \| null | no |  |

```json
{
  "grant_type": "string",
  "username": "string",
  "password": "string",
  "scope": "",
  "client_id": "string",
  "client_secret": "string"
}
```

## Responses

### 200 — Login successful without MFA challenge

### 401 — Invalid credentials or MFA verification required

### 422 — Validation Error

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `detail` | object[] | no |  |
| `detail[].loc` | string | integer[] | yes |  |
| `detail[].msg` | string | yes |  |
| `detail[].type` | string | yes |  |
| `detail[].input` | object | no |  |
| `detail[].ctx` | object | no |  |

```json
{
  "detail": [
    {
      "loc": [
        null
      ],
      "msg": "string",
      "type": "string",
      "input": null,
      "ctx": {}
    }
  ]
}
```

## Example

```bash
curl -X POST "$PINTER_URL/api/identity/token" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```
