# Redeem a sign-in code

A terminal trades the page's code and its own secret for a session.

POST `/api/v1/sign-in/code`

**cURL**

```shell
curl -X POST 'https://www.prufy.dev/api/v1/sign-in/code' \
  -H 'content-type: application/json' \
  -d '{
  "verifier": "Xh2kP9qL5mN8rT3vW6yZ1bC4dF7gJ0sA2eH5jK8nQ4u",
  "code": "K7QM-4TZP"
}'
```

**Node.js**

```javascript
const response = await fetch("https://www.prufy.dev/api/v1/sign-in/code", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    verifier: "Xh2kP9qL5mN8rT3vW6yZ1bC4dF7gJ0sA2eH5jK8nQ4u",
    code: "K7QM-4TZP",
  }),
})
const data = await response.json()
```

**Python**

```python
import requests

response = requests.post(
    "https://www.prufy.dev/api/v1/sign-in/code",
    json={
        "verifier": "Xh2kP9qL5mN8rT3vW6yZ1bC4dF7gJ0sA2eH5jK8nQ4u",
        "code": "K7QM-4TZP",
    },
)
data = response.json()
```

Response 200 OK

```json
{
  "signedIn": true
}
```

`verifier` is the secret whose SHA-256 the terminal sent when it asked for the link. It never left the terminal before this, so the code alone, read off someone's screen, is no use.

The code lasts 10 minutes from when the button was pressed. Case, spaces and the dash don't matter. After 5 wrong codes the sign-in is used up.

On success the session arrives in `Set-Cookie`, never in the body, the same way the first claim's does.

## Authentication

No cookie. The token in the request is the whole credential. [How sessions work](https://www.prufy.dev/docs/authentication.md).

## Body

JSON, with `content-type: application/json`.

- `verifier` string required

  The secret the terminal kept. Its SHA-256 is what it sent as `terminal`.

  - At most 200 characters
- `code` string required

  The code the sign-in page showed.

  - At most 40 characters

## Response

`200 OK`, with every field below present. Times are ISO 8601 strings in UTC.

- `signedIn` boolean

  True when the code was right. The session comes back in `Set-Cookie`, never in the body.

## Errors

| Status | Kind | When |
| --- | --- | --- |
| 400 | `bad_request` | The body isn't JSON, or doesn't match the shape below. `message` names the first field to fix, and `fields` lists each one with its path. |
| 413 | `payload_too_large` | The body is over 16 KB. No route takes anything near that. |
| 429 | `rate_limited` | This network has used 30 links and codes in the last hour. |

Any route can also answer `500` with `internal_error`. Every error has the same shape, described in [Errors](https://www.prufy.dev/docs/errors.md).

---

Every page of these docs, as a list: https://www.prufy.dev/llms.txt
