Перейти к содержимому

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.

SettingMeaning
API keyGenerated: 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 callersNetwork objects: the addresses of your servers that may call the API with this key. Empty = any address.
First factorMFA 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 profileAn allow carries user: username, display name, e-mail and groups. Attributes are returned either way.
Groups filterGroups returned in user.groups, one per line; a name ending in * matches as a prefix. Empty = all groups.
Require MFAOff: 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.

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.

  1. Start. On each sign-in your server calls POST /api/v1/verify/start with the username, the end user’s IP address and an idempotency key.

  2. Branch on result.

    • allow — let the user in; use user and attributes to build the session.
    • deny — refuse; show message.
    • challenge — show what challenge.prompt asks for: the number to pick on the phone, a code field, or a “check your phone” wait for a push.
  3. Finish the challenge. Long-poll GET /api/v1/verify/<tx>?wait=25 until the result is no longer pending, and/or send a typed code to POST /api/v1/verify/<tx>/code. When the user gives up, call POST /api/v1/verify/<tx>/cancel.

  4. 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.

Terminal window
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"}}'
FieldRule
usernameRequired, 1–256 characters. Resolved like every other sign-in (local or directory user).
passwordRequired with First factor = Password; refused (422 API_PASSWORD_NOT_EXPECTED) with MFA only. Never stored or logged.
client_ipThe end user’s IP address. Network and country conditions need it.
request_keyOptional, 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.actionOptional, one line, ≤ 100: shown in the push and e-mail, e.g. “Sign in to Billing”.
context.device, context.locationOptional, ≤ 100 each: recorded in the sign-in log.
context.user_agentOptional, ≤ 255: the end user’s browser.
context.langOptional: 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.

User’s methodpromptYour server then
TOTPcodeShow a code field; send the code with POST …/code. poll_after is null — nothing to wait for.
E-mail codecodeThe 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.
TelegrampushA push with buttons: long-poll until it is answered.
Web Pushnumber or pushShow number when number matching is on; long-poll. With code_fallback: true also show a code field for the device’s offline code.
Terminal window
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.

Terminal window
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.

The user gave up: the push is withdrawn and the result becomes deny mfa_cancelled. Calling it again returns the same final state.

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.

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"] } }
FieldContent
userThe user’s profile. Absent when Return the user profile is off.
user.usernameThe OkYouIn username, as the Access Log shows it.
user.display_name, user.emailThe user’s values, or null.
user.groupsThe user’s groups (local and directory) that pass Groups filter, sorted; [] when none.
attributesThe 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.

Branch on result (and challenge.prompt), never on reason — log reason together with tx.

resultreasonMeaning
allowmfa_verifiedSecond factor passed.
allowmfa_not_requiredNo MFA needed (policy or application settings).
allowmfa_cachedMFA of a recent sign-in from the same address (MFA cache).
challengemfa_requiredThe second factor started: see challenge.
challengeinvalid_codeWrong code; attempts_left says how many tries remain.
denydeniedRefused — the same answer for every cause (unknown user, wrong password, policy…). The sign-in log says which.
denymfa_deniedThe user denied it or reported it as not theirs.
denymfa_failedToo many wrong codes.
denymfa_cancelledCancelled by your server.
denymfa_supersededA newer sign-in of the same user replaced it.
denyrate_limitedToo many attempts or pushes; message names the minutes.
denydelivery_failedThe code or push could not be sent.
denyerrorInternal error: no access, try again later.
expiredmfa_timeoutNot 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.

HTTPcodeWhen
401API_KEY_MISSING, API_KEY_INVALIDNo key, or one OkYouIn does not accept.
403API_TLS_REQUIREDCalled over plain HTTP — rotate the key.
403API_SOURCE_NOT_ALLOWEDYour server’s address is not in Allowed callers.
404API_TX_NOT_FOUNDUnknown or expired tx, or another application’s.
409API_CODE_NOT_ACCEPTEDThis sign-in takes no code.
409API_REQUEST_KEY_REUSEDThe request_key was already used with a different body.
409API_REQUEST_IN_PROGRESSThe first call with this request_key is still running: retry after Retry-After.
422VALIDATION_ERROR, API_PASSWORD_REQUIRED, API_PASSWORD_NOT_EXPECTED, API_CLIENT_IP_NOT_EXPECTEDA field is missing or wrong, or does not fit the settings.
429RATE_LIMITEDToo many requests: wait Retry-After seconds. Limits apply per caller address and per application.
503DATABASE_UNAVAILABLE, CLUSTER_NO_PRIMARYOkYouIn cannot decide right now: no access, retry later.

Error bodies have the shape {"detail": "…", "code": "…", "field": "…"}.

  • Fail closed. Only allow lets the user in.
  • Keep tx server-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_key per attempt and reuse it on a retry after a network error: the retry gets the same answer, not a second push.
  • Send client_ip when 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.