Go to developer

How OAuth Verify Works

Understand the protocol and the trust boundary before copying snippets.

On this page

Lifecycle

BROWSER                 YOUR BACKEND              KEYRA                USER
   │                          │                      │                    │
   │ Start (publishable cp_*) │                      │                    │
   ├────────────────────────────────────────────────►│                    │
   │ authorize_url            │                      │                    │
   │◄────────────────────────────────────────────────┤                    │
   │ Open popup/redirect      │                      │                    │
   │                          │                      │◄─── verify ────────┤
   │ authorization code       │                      │                    │
   │◄────────────────────────────────────────────────┤                    │
   │ Token exchange (PKCE)    │                      │                    │
   ├────────────────────────────────────────────────►│                    │
   │ access_token             │                      │                    │
   │ (= verification_token)   │                      │                    │
   │◄────────────────────────────────────────────────┤                    │
   │ POST token to backend    │                      │                    │
   ├─────────────────────────►│                      │                    │
   │                          │ POST /verify/validate│                    │
   │                          ├─────────────────────►│                    │
   │                          │ valid + user         │                    │
   │                          │◄─────────────────────┤                    │
   │                          │ Create YOUR session  │                    │
   │ Set app session cookie   │                      │                    │
   │◄─────────────────────────┤                      │                    │
  1. Browser (or your server) starts authorization with PKCE + state.
  2. KEYRA returns an authorize_url to the hosted verification UI.
  3. User completes verification on their device.
  4. Browser receives an authorization code (popup postMessage or redirect query).
  5. Browser exchanges code + code_verifier at POST /oauth/token.
  6. Browser sends access_token to your backend.
  7. Backend calls POST /verify/validate (single-use) then creates your session.

Two start endpoints

KEYRA exposes two public start handlers that insert into the same hosted_login_challenges table. They are not thin aliases — defaults and response shapes differ.

/oauth/authorize/init/verify/start
Used by@keyra/web-sdk createKeyraAuthPaste script; createKeyraServer / Java verification
Default scopeopenid profile phoneverify
Response id fieldauth_request_idverification_id (+ auth_request_id)
Extra status fieldstatus: "pending"

Challenge lifetime defaults to ~600s (configurable via HOSTED_LOGIN_CHALLENGE_TTL_SECONDS, clamped 120–3600).

Tokens

NameMeaning
access_tokenReturned by /oauth/token. Used for userinfo Bearer and validate.
verification_token / verificationTokenSame value as access_token — aliased by paste script and Web SDK for DX.
Authorization codeShort-lived code from hosted UI; exchanged with PKCE verifier.

Who does what

ActorDoesMust not
BrowserStart with publishable id; PKCE; popup/redirect; token exchange; POST token to your APIHold secret keys; treat browser success as final login
Your backend/verify/validate; map user; create sessionSkip validate
KEYRAHosted verify UI; issue code/token; consume on validateCreate your app session cookie

State & PKCE

state is required by the start APIs. Web SDK and paste script generate it and verify it on callback (CSRF protection). PKCE S256 is required — see PKCE.