Verify API
The Verify API lets your own application’s backend ask OkYouIn to run a sign-in for one of its users. Your server sends the username (and the password, if OkYouIn should check it); OkYouIn applies the policy, sends the user’s second factor — TOTP, an e-mail code or Approve link, Telegram, or Web Push with number matching — and answers allow, deny or challenge. An allow carries the user’s profile and the attributes your application rules assign, so your application can set up the session and the user’s role from one answer.
The API is server to server: your backend calls it, never the browser or a mobile app. There is no SDK — five HTTPS calls with JSON bodies.
Create the application from the Custom app (API / SDK) template (Access ▸ Applications ▸ Add application). Its Connect tab shows every call below with your server’s URL and key filled in.
Settings
Section titled “Settings”| Setting | Meaning |
|---|---|
| API key | Generated: oky_live_<key-id>_<secret>. Stored encrypted; reveal and copy are audited. |
| Previous key valid (minutes) | After a key change the previous key keeps working this long, so your servers can switch over. 0 = at once; at most 1440. Default 60. |
| Allowed callers | Network objects: the addresses of your servers that may call the API with this key. Empty = any address. |
| First factor | MFA only (default) — your application checked the password itself; OkYouIn adds the second factor. Password — your server sends the password and OkYouIn checks it against the local user or directory. |
| Return the user profile | An allow carries user: username, display name, e-mail and groups. Attributes are returned either way. |
| Groups filter | Groups returned in user.groups, one per line; a name ending in * matches as a prefix. Empty = all groups. |
| Require MFA | Off: sign-ins the policy allows get in without a second factor. |
| MFA cache (minutes) | A recent MFA of the same user from the same client IP is reused. Needs First factor = Password. |
Keys and rotation
Section titled “Keys and rotation”Every call sends the key as a bearer token:
Authorization: Bearer oky_live_k3m7q2x5c9ab_Xq...To rotate, generate a new key in Settings and save. The previous key keeps working for
Previous key valid (minutes); GET /api/v1/verify/ping tells each caller which key it is
using. Once every server uses the new one, you can revoke the previous key early instead of
waiting for the grace to end. The first use of the previous key after a rotation, and
rejected keys, are recorded in the audit log.
The API refuses plain HTTP before it reads the key, with 403 API_TLS_REQUIRED — the key
has already crossed the network unencrypted, so generate a new one.
The flow
Section titled “The flow”-
Start. On each sign-in your server calls
POST /api/v1/verify/startwith the username, the end user’s IP address and an idempotency key. -
Branch on
result.allow— let the user in; useuserandattributesto build the session.deny— refuse; showmessage.challenge— show whatchallenge.promptasks for: the number to pick on the phone, a code field, or a “check your phone” wait for a push.
-
Finish the challenge. Long-poll
GET /api/v1/verify/<tx>?wait=25until the result is no longerpending, and/or send a typed code toPOST /api/v1/verify/<tx>/code. When the user gives up, callPOST /api/v1/verify/<tx>/cancel. -
Grant access only on
result: "allow". Anything else —deny,expired, an HTTP error, a timeout, an unreadable answer — means no access.
All paths are below your server’s public URL, e.g. https://mfa.example.com/api/v1/verify/start.
Bodies are JSON (Content-Type: application/json), at most 16 KB. Every decision is an HTTP
200; HTTP errors are reserved for problems with the call itself.
POST /api/v1/verify/start
Section titled “POST /api/v1/verify/start”curl -sS -X POST https://mfa.example.com/api/v1/verify/start \ -H "Authorization: Bearer $OKYOUIN_API_KEY" \ -H "Content-Type: application/json" \ -d '{"username": "alice", "client_ip": "203.0.113.7", "request_key": "login-8f2c41", "context": {"action": "Sign in to Billing"}}'| Field | Rule |
|---|---|
username | Required, 1–256 characters. Resolved like every other sign-in (local or directory user). |
password | Required with First factor = Password; refused (422 API_PASSWORD_NOT_EXPECTED) with MFA only. Never stored or logged. |
client_ip | The end user’s IP address. Network and country conditions need it. |
request_key | Optional, 1–128 characters A–Z a–z 0–9 . _ : -. A retry with the same key gets the same answer instead of a second push. |
context.action | Optional, one line, ≤ 100: shown in the push and e-mail, e.g. “Sign in to Billing”. |
context.device, context.location | Optional, ≤ 100 each: recorded in the sign-in log. |
context.user_agent | Optional, ≤ 255: the end user’s browser. |
context.lang | Optional: the language of message (de, de-DE…); otherwise Accept-Language. |
Answers (tx is always present — quote it to find the entry in the sign-in log):
{ "tx": "6f1c2a9e-8d4b-4a7f-b3c1-2e5d9f0a7b64", "result": "deny", "reason": "denied", "message": "Sign-in denied." }{ "tx": "6f1c2a9e-8d4b-4a7f-b3c1-2e5d9f0a7b64", "result": "challenge", "reason": "mfa_required", "message": "Approve the sign-in on your phone and pick 42.", "challenge": { "method": "webpush", "prompt": "number", "number": 42, "code_fallback": true, "digits": 6, "approve_link": false, "sent_to": null, "attempts_left": 3, "expires_at": "2026-11-22T10:02:00Z", "expires_in": 120, "poll_after": 2 } }An allow without a challenge (MFA not required, or cached) carries user and attributes
right away — see What an allow returns.
What start returns per method
Section titled “What start returns per method”| User’s method | prompt | Your server then |
|---|---|---|
| TOTP | code | Show a code field; send the code with POST …/code. poll_after is null — nothing to wait for. |
| E-mail code | code | The code goes out by e-mail (sent_to shows where, masked). With approve_link: true the e-mail also has Approve / Deny links: show the code field and long-poll. |
| Telegram | push | A push with buttons: long-poll until it is answered. |
| Web Push | number or push | Show number when number matching is on; long-poll. With code_fallback: true also show a code field for the device’s offline code. |
GET /api/v1/verify/{tx}?wait=0..25
Section titled “GET /api/v1/verify/{tx}?wait=0..25”curl -sS "https://mfa.example.com/api/v1/verify/6f1c2a9e-8d4b-4a7f-b3c1-2e5d9f0a7b64?wait=25" \ -H "Authorization: Bearer $OKYOUIN_API_KEY"Waits up to wait seconds (at most 25) for the push or e-mail link to be answered, then
returns the state: pending (call again at once), allow, deny or expired. A client that
does not long-poll can poll every poll_after seconds instead. Stop at expires_at. A
finished tx keeps answering its final state for 10 minutes, then 404.
POST /api/v1/verify/{tx}/code
Section titled “POST /api/v1/verify/{tx}/code”curl -sS -X POST https://mfa.example.com/api/v1/verify/6f1c2a9e-8d4b-4a7f-b3c1-2e5d9f0a7b64/code \ -H "Authorization: Bearer $OKYOUIN_API_KEY" \ -H "Content-Type: application/json" \ -d '{"code": "123456"}'A right code → allow. A wrong one → challenge with reason invalid_code and
attempts_left; the third wrong code → deny mfa_failed. If the push or e-mail link was
approved in the meantime, the approval decides. A round that takes no code (Telegram, a push
without fallback) answers 409 API_CODE_NOT_ACCEPTED.
POST /api/v1/verify/{tx}/cancel
Section titled “POST /api/v1/verify/{tx}/cancel”The user gave up: the push is withdrawn and the result becomes deny mfa_cancelled.
Calling it again returns the same final state.
GET /api/v1/verify/ping
Section titled “GET /api/v1/verify/ping”A connection check — which application and which key you are using. Nothing is logged.
{ "application": { "id": "0b7e…", "name": "Billing portal", "enabled": true }, "key": "current", "previous_key_valid_until": null, "server_time": "2026-11-22T10:00:00Z", "api_version": "1" }key is current, previous (a rotated key still in its grace) or legacy.
What an allow returns
Section titled “What an allow returns”Only result: "allow" carries user and attributes; deny, challenge, pending and expired
answers never have these keys.
{ "tx": "6f1c2a9e-8d4b-4a7f-b3c1-2e5d9f0a7b64", "result": "allow", "reason": "mfa_verified", "message": null, "attempts_left": null, "challenge": null, "user": { "username": "alice", "display_name": "Alice Example", "email": "alice@example.com", "groups": ["billing-admins", "vpn-users"] }, "attributes": { "role": "admin", "beta": true, "teams": ["ops"] } }| Field | Content |
|---|---|
user | The user’s profile. Absent when Return the user profile is off. |
user.username | The OkYouIn username, as the Access Log shows it. |
user.display_name, user.email | The user’s values, or null. |
user.groups | The user’s groups (local and directory) that pass Groups filter, sorted; [] when none. |
attributes | The matched application rule’s attributes, then the template defaults the rule leaves out: a string, true / false, or a list of strings (a name given several times). {} when none; always present on an allow. |
Set the attributes on the application’s Rules tab: for example a rule for the group
billing-admins with the attribute role = admin, and the Default rule with role = viewer.
Names starting with okyouin: are reserved.
Results and reasons
Section titled “Results and reasons”Branch on result (and challenge.prompt), never on reason — log reason together with
tx.
result | reason | Meaning |
|---|---|---|
| allow | mfa_verified | Second factor passed. |
| allow | mfa_not_required | No MFA needed (policy or application settings). |
| allow | mfa_cached | MFA of a recent sign-in from the same address (MFA cache). |
| challenge | mfa_required | The second factor started: see challenge. |
| challenge | invalid_code | Wrong code; attempts_left says how many tries remain. |
| deny | denied | Refused — the same answer for every cause (unknown user, wrong password, policy…). The sign-in log says which. |
| deny | mfa_denied | The user denied it or reported it as not theirs. |
| deny | mfa_failed | Too many wrong codes. |
| deny | mfa_cancelled | Cancelled by your server. |
| deny | mfa_superseded | A newer sign-in of the same user replaced it. |
| deny | rate_limited | Too many attempts or pushes; message names the minutes. |
| deny | delivery_failed | The code or push could not be sent. |
| deny | error | Internal error: no access, try again later. |
| expired | mfa_timeout | Not answered in time. |
message is text for the end user, in the requested language; it never reveals which check
failed. With First factor = Password the answer does not reveal whether a user exists; with
MFA only, a challenge necessarily reveals it.
Errors
Section titled “Errors”| HTTP | code | When |
|---|---|---|
| 401 | API_KEY_MISSING, API_KEY_INVALID | No key, or one OkYouIn does not accept. |
| 403 | API_TLS_REQUIRED | Called over plain HTTP — rotate the key. |
| 403 | API_SOURCE_NOT_ALLOWED | Your server’s address is not in Allowed callers. |
| 404 | API_TX_NOT_FOUND | Unknown or expired tx, or another application’s. |
| 409 | API_CODE_NOT_ACCEPTED | This sign-in takes no code. |
| 409 | API_REQUEST_KEY_REUSED | The request_key was already used with a different body. |
| 409 | API_REQUEST_IN_PROGRESS | The first call with this request_key is still running: retry after Retry-After. |
| 422 | VALIDATION_ERROR, API_PASSWORD_REQUIRED, API_PASSWORD_NOT_EXPECTED, API_CLIENT_IP_NOT_EXPECTED | A field is missing or wrong, or does not fit the settings. |
| 429 | RATE_LIMITED | Too many requests: wait Retry-After seconds. Limits apply per caller address and per application. |
| 503 | DATABASE_UNAVAILABLE, CLUSTER_NO_PRIMARY | OkYouIn cannot decide right now: no access, retry later. |
Error bodies have the shape {"detail": "…", "code": "…", "field": "…"}.
Rules for your server
Section titled “Rules for your server”- Fail closed. Only
allowlets the user in. - Keep
txserver-side, in your login session — never take it from the browser. The allow must belong to the sign-in you started, for the same user. - Send a
request_keyper attempt and reuse it on a retry after a network error: the retry gets the same answer, not a second push. - Send
client_ipwhen you know it: network and country rules need it. - Give each call a timeout above 30 seconds — a long poll answers within 25.
- Keep the key in a secret store and call over HTTPS only.
- In a high-availability cluster, a node cut off from the database refuses every verify call
with
503: point your servers at both nodes or at your load balancer.
Every call — allow, deny and each MFA round — is in Logging ▸ SSO sign-in log and the Access log, with the answer’s user profile and attributes. The policy tester shows what an allow would carry for a given user.