These helpers implement the server-side OAuth Authorization Code
flow. VentureKit does not enable the Cognito Hosted UI; the SPA
runs the redirect dance, the API exchanges the code with the IdP
back-channel (so the client_secret never leaves the server).
Function
Signature
Description
generateOAuthState()
() => string
Mint a random URL-safe state token. The /start route returns it AND pins it to the browser via an HttpOnly cookie.
verifyOAuthState(fromQuery, fromCookie)
(string?, string?) => boolean
Constant-time compare for the /complete CSRF check.
buildAuthorizeUrl(input, env?)
(BuildAuthorizeUrlInput) => Promise<string>
Build the IdP authorize URL the SPA navigates to. Loads client_id from Secrets Manager.
OTP toolkit for the “we’ll text you a 6-digit code” gate. Pluggable
storage via VerificationCodeStore; channel is opaque ('email' /
'whatsapp' / anything else the application defines).
Function
Signature
Description
generateVerificationCode(length?)
(number?) => string
crypto.randomInt-backed digits. Default 6, range 4–10.
Mint + persist + return plaintext for delivery. Overwrites any previous code for the same (channel, identifier).
verifyVerificationCode(input)
(VerifyVerificationCodeInput) => Promise<void>
Constant-time check; deletes on success, increments attempts on mismatch, wipes after maxAttempts. Throws verification_failed (HTTP 401).
createInMemoryVerificationCodeStore()
() => VerificationCodeStore
Tests / vk dev only.
The placeholder secret VentureKit provisions for each declared
AuthIntent.federated provider is named
venturekit/<project>/<stage>/auth/<intent.id>/<provider> and holds
{"clientId":"PLACEHOLDER","clientSecret":"PLACEHOLDER"}. Populate it
after the first deploy: