{BASE} = https://authentica-merge-integration.t2.sa.

Sandbox (test mode)

Every app has two secrets on the same clientId: the live secret and a test secret (test_…), both shown on the app’s credentials panel in the portal. The secret you authenticate with decides the mode of the whole flow - your integration code is identical in both, only the configured secret differs: Build and test the whole integration with the test secret; going live is swapping in the live secret - nothing else changes. A test session’s outcome can never be read with the live secret (and vice versa), so a sandbox verification can never be mistaken for a real one.

Request body

You register exactly one URL for the app: returnUrl, the GET landing page. There is no second URL to register - nothing is delivered to your server, so there is no receiver to point at. See Get your credentials.

returnUrl is matched as a whole string

Registration is an exact, case-sensitive, whole-string comparison against the URLs on your app. Not a prefix match, not a host match:
  • no trailing slash unless the registered value has one
  • no query string appended
  • http vs https, www vs bare host, and localhost ports all matter
Any mismatch fails the session create with invalid_return_url - the browser never leaves your app, so this shows up in your own logs, not the user’s.

Channel

Any other value → invalid_channel. A missing or unusable destination → destination_required.

Nafath

On channel: "nafath" the hosted page shows a confirmation number instead of code boxes and waits while the user approves the request in the Nafath app; when Nafath reports the outcome the browser is redirected to your returnUrl exactly as on sms, and GET /session/{id} answers with "method": "nafath". Two behaviors are deliberate:
  • The passkey shortcut never runs on a nafath session. However recognized the browser is, identity is proven in the Nafath app on every sign-in, and no passkey enrollment is offered afterwards.
  • There is no code fallback. A rejected or expired approval fails the session (reason: "nafath_rejected" / "nafath_expired"); start a new session to retry.
  • One outstanding request per national ID. While your app already has a Nafath session pending for a national ID, creating another does not race a second challenge to the same person’s app - the call succeeds and hands back into the pending flow: the response carries the pending session’s sessionId, a fresh handoff, and "resumed": true, and the hosted page shows the user their active request and its confirmation number. Your state, returnUrl and userRef from the new call replace the pending flow’s. A fresh session is created once the pending flow completes, fails, or its challenge window elapses (180 seconds - the official Nafath request timeout, which also allows only one request per window on Nafath’s side).

The service field

service names the Nafath action the user is approving - it is what the Nafath app shows the user as the reason for the request. Authentica supports the Login service only. Omit the field, or send "Login" (matching is case-insensitive); any other value is rejected with 400 invalid_service before a session exists. The service is part of the security check on the answer: the approval callback must name the same service the challenge was created for, and a mismatch is treated as a rejection.

Operation sensitivity

How risky the action behind this session is. Set by your backend when creating the session: Sensitivity is per session, so the same integration can use "normal" on one route and "sensitive" on another. Anything other than those two values → invalid_operation_sensitivity.

Example

curl

Idempotency

POST /session is the call your HTTP client retries on timeout, and the one that costs money in SMS - so a retry must not text the user twice. Send an optional Idempotency-Key header (any unique string per logical attempt, up to 255 characters), following the IETF Idempotency-Key draft: Only a successful response is stored for replay - a failure is retryable as normal. Keys are retained for 24 hours and are scoped to your client_id.
Do not reuse one key for two different attempts. “Retry of the same attempt” gets the same key; “the user pressed send again” gets a new one - otherwise the second attempt either replays a stale response or fails with 422.

Choosing a theme

An app can have several themes attached to it in the portal, one of which is its default. Leave this alone and every session renders that default - most integrations never need anything else. To pick a different one for a single session, name it on the create call. The header and the query parameter do the same thing; use whichever fits your HTTP client:
The value is the theme’s id, copied from the app’s Themes tab in the portal (Integrate → your app → Themes, or Manage themes in Page Studio). It must be a theme attached to this app - one belonging to another app, or to another client, is refused with 400 and errorCode: "theme_not_attached" rather than quietly falling back, so a mistyped id is visible immediately instead of shipping the wrong brand to your users. The choice is fixed for the life of the session: it is recorded when the session is created, so a reload of the hosted page renders the same theme.

Choosing a language

The hosted page ships in English and Arabic, plus any language the theme’s Texts & languages tab adds, and opens in the theme’s default language. To open it in a specific one for a session - the language the user already picked on your own site, say - name it on the create call, the same way as the theme. Header and query parameter are equivalent:
The value is a language tag (en, ar, en-GB); case does not matter. It must be one the session’s theme can render - a value that is not a tag is refused with 400 and errorCode: "invalid_language", and a well-formed tag the theme has no texts for with errorCode: "language_not_supported" - so a typo is visible in your logs rather than silently opening the page in the wrong language. Two things stay as they were:
  • The user can still switch language on the page itself; the header only decides what they see first.
  • The browser SDK’s optional lang on AuthenticaVerify.start(...) still works and, when set, overrides the header for that open. You need one or the other, not both; the header is the simpler choice because your server already knows the user’s language.

Success response

HTTP 200, isSuccess: true:

The handoff token

handoff is the capability that opens the hosted verify page. It is:
  • Single-use - redeemed the first time it is POSTed to verifyUrl. A replay returns 400.
  • Short-lived - TTL expiresInSeconds (120 s today). Create the session at the moment the user is ready to verify, not minutes ahead.
  • URL-forbidden - it must only ever travel in a request body. GET {verifyUrl} with any query string is rejected with 400.
Pass verifyUrl and handoff down to the browser together, and hand off with an auto-submitting form - see Frontend overview.

Client platform (web / mobile)

platform tells Authentica which kind of client finishes the flow. Your backend sets it per session - a browser cannot choose it, because it rides on the authenticated POST /session call. It only changes which returnUrl schemes are accepted; the return itself is unchanged. Either way the return carries the same ?session_id=…&state=…; only the accepted returnUrl schemes differ. A mobile return is just that same ?session_id=&state= appended to your registered deep link. For the full mobile integration, see Mobile apps.

Common errors

What to do with the response

  1. Store sessionId next to state on the pending action, along with what the action actually is.
  2. Return verifyUrl and handoff - and nothing else - to your frontend:
The browser POSTs the token into the hosted page. When the user comes back, your landing page reads the outcome with GET /session/{sessionId}.

Where to call this

Only from your backend, inside whichever route owns the action your frontend triggered - /verify/start, /payments/confirm, /profile/change-phone, and so on.