# Request a challenge

Get a challenge to sign

`POST https://auth.cadmos.finance/v1/external-auth/challenge`

Answers a sign-in message that expires in two minutes. Sign it unchanged with EIP-191 (`signMessage`) using your key. Check before signing that it names `auth.cadmos.finance`, your identity and the audience `cadmos-pay-be`.

## Authentication

This endpoint accepts requests without a bearer token.

## Example requests

```bash
curl --fail-with-body 'https://auth.cadmos.finance/v1/external-auth/challenge' \
  -H "Content-Type: application/json" \
  --data-binary @- <<JSON
{
  "identityId": "${CADMOS_IDENTITY_ID:?Set CADMOS_IDENTITY_ID}",
  "address": "${SIGNING_ADDRESS:?Set SIGNING_ADDRESS}"
}
JSON
```

```javascript
const { CADMOS_IDENTITY_ID, SIGNING_ADDRESS } = process.env;
if (!CADMOS_IDENTITY_ID || !SIGNING_ADDRESS) {
  throw new Error("Set CADMOS_IDENTITY_ID and SIGNING_ADDRESS");
}

const url = new URL("https://auth.cadmos.finance/v1/external-auth/challenge");
const body = {
  "identityId": CADMOS_IDENTITY_ID,
  "address": SIGNING_ADDRESS
};
const response = await fetch(url, {
  method: "POST",
  redirect: "error",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
});
console.log(response.status, await response.json());
```

```python
from http.client import HTTPSConnection
import json
import os

conn = HTTPSConnection("auth.cadmos.finance", timeout=30)
path = "/v1/external-auth/challenge"
body = json.dumps({
  "identityId": os.environ["CADMOS_IDENTITY_ID"],
  "address": os.environ["SIGNING_ADDRESS"]
})
headers = {
    "Content-Type": "application/json",
}
conn.request("POST", path, body=body, headers=headers)
response = conn.getresponse()
print(response.status, response.read().decode())
conn.close()
```

## Request body

`application/json`

[ChallengeRequest](https://cadmospay.com/developers/schemas/challenge-request.md)

Only the listed properties are accepted.

- `identityId` (string, required, pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$). The identity id Cadmos gave you.
- `address` (string, required, pattern ^0x[0-9a-fA-F]{40}$). Your signing key's address, as registered with Cadmos.

## Responses

### 200

The challenge.

[Challenge](https://cadmospay.com/developers/schemas/challenge.md)

```json
{
  "identityId": "a08cccbc-f085-4289-bd48-9b2fb55acd14",
  "challengeId": "509ae372-5c3e-45f2-a848-b311680b4da3",
  "message": "<exact sign-in message returned by Cadmos>",
  "expiresAt": "2026-11-17T09:02:00.000Z"
}
```

### 400

Malformed request.

[Error](https://cadmospay.com/developers/schemas/error.md)

### 401

Unknown or disabled identity or address, wrong signature, or a challenge already used or expired.

[Error](https://cadmospay.com/developers/schemas/error.md)

### 503

Sign-in is unavailable. Retry later.

[Error](https://cadmospay.com/developers/schemas/error.md)
