WebApps Authentication
Document information
- Canonical URL:
/docs/05_apps-webhooks-and-surfaces/webapps/46-Webapps_Authentication - Version:
2026-10-18 - Tags:
webapps,authentication,jwt,guides
Published custom WebApps (type: webapp) authenticate end users with a token issued by your login ProcessFlow. Process execution still runs as the configured webapp_user_id service account. End-user identity lives in the token claims and in process_input.auth / process_input.auth_token.
Do not send a product type: access token (from browser POST /api/v1/auth/login) as the WebApp session. That token is for console /api/v1/*, not the published WebApp host. Login ProcessFlows may call product login server-side only to verify credentials, then discard that token and mint webapp_access (see Verify credentials).
GET HTML for the published page stays public. Page JavaScript should gate UI. Runtime auth applies to POST and /api/* under the WebApp host.
Architecture (login + protected)
Browser
│ POST login (auth_require: false)
▼
Login ProcessFlow
→ verify credentials (platform user or app-owned store)
→ jwt.issueWebappAccess({ user_id, email, role })
→ return access_token (and/or Set-Cookie via runtime)
│
Browser keeps Bearer in memory (or cookie for same-origin)
│ POST protected action with Authorization: Bearer / cookie
▼
Protected ProcessFlow (auth_require: true)
→ runtime verifies JWT, injects process_input.auth
→ step reads process_input.auth (optional role checks)
→ business logic as webapp_user_id
Use one WebApp with two processes (login vs data) or two WebApps that share the same login/session design. Keep auth_require off on the login surface; turn it on for protected POSTs and /api/*.
For admin-only / role-restricted surfaces, also see WebApps: admin-only access.
Choose an auth transport
Set auth_transport in WebApp Settings (or POST/PUT /api/v1/webapps).
| Value | Login response | Client sends later | Cookie rewrite |
|---|---|---|---|
cookie (default) | Set-Cookie: tf_session (HttpOnly, Secure, SameSite=Lax) | Cookie | Yes |
bearer | JWT in JSON (access_token) | Authorization: Bearer | No |
both | Cookie and JSON body | Bearer preferred, cookie fallback | Yes |
Use Cookie for same-origin HTML forms. Use Bearer for custom JavaScript apps (including cross-origin callers). Use Both only while migrating; JavaScript can still read the JSON copy of the token, so it is not XSS-resistant.
CORS on the published runtime keeps Access-Control-Allow-Credentials: false. Cross-origin clients must use Bearer. Do not expect cookies to work across origins.
Verify credentials for Tealfabric users
When the end user is an active tenant user in Tealfabric (console Users row), the login ProcessFlow must prove email/password before minting a WebApp token. Two supported server-side options:
Option A — Product login verify-then-mint (recommended for platform users)
Call product login inside the step as webapp_user_id via tf.api / api. Inspect success, read the user identity, discard the console access_token, then call jwt.issueWebappAccess. The browser never stores the product token.
const email = String(process_input.email ?? "").trim();
const password = String(process_input.password ?? "");
if (!email || !password) {
return {
success: false,
error: { code: "MISSING_CREDENTIALS", message: "Email and password are required" }
};
}
// Do not log password or process_input.
const login = await tf.api.post("/api/v1/auth/login", { email, password });
if (!login || login.success === false) {
return {
success: false,
error: { code: "INVALID_CREDENTIALS", message: "Invalid email or password" }
};
}
// Product envelope: { success, data: { user_id, email, role, access_token, … } }
const data =
login.data && typeof login.data === "object" && !Array.isArray(login.data)
? (login.data as Record<string, unknown>)
: {};
const endUserId = String(data.user_id ?? "").trim();
const endEmail = String(data.email ?? email).trim();
const endRole = String(data.role ?? "user").trim() || "user";
if (!endUserId) {
return {
success: false,
error: { code: "LOGIN_IDENTITY_MISSING", message: "Login succeeded without user id" }
};
}
// Discard data.access_token / data.refresh_token — do not return them to the browser.
const issued = jwt.issueWebappAccess({
user_id: endUserId,
email: endEmail,
role: endRole
});
return {
success: true,
access_token: issued.access_token,
token_type: issued.token_type,
expires_at: issued.expires_at,
data: { authenticated: true, user_id: endUserId, role: endRole }
};
Requires the ProcessFlow api capability (needed for tf.api). Always require a non-empty data.user_id before minting.
Option B — App-owned credential store
For users that are not platform Users (custom registration tables), look up the account with tenantDb / DataPool / an integration, compare a one-way password hash, then mint. Never store or log raw passwords.
const email = String(process_input.email ?? "").trim();
const password = String(process_input.password ?? "");
// Load row by email; compare hash; set endUserId / endRole from the row.
const issued = jwt.issueWebappAccess({
user_id: endUserId,
email,
role: endRole
});
return {
success: true,
access_token: issued.access_token,
token_type: issued.token_type,
expires_at: issued.expires_at,
data: { authenticated: true, user_id: endUserId }
};
jwt.issueWebappAccess contract
Available in WebApp-triggered ProcessFlow steps as root jwt and tf.jwt. There is no generic jwt.sign.
| Input | Required | Description |
|---|---|---|
user_id | Yes | End-user id placed in JWT sub / claims |
email | No | Copied into claims (string) |
role | No | App-defined role string (for example user, member, tenant_admin) |
expires_in | No | Duration string (for example 15m). Capped by WEBAPP_JWT_EXPIRES_IN (default 15m) |
Bound automatically from the executing WebApp context (do not pass these):
tenantIdwebapp_idtype: "webapp_access"- signature secret
WEBAPP_JWT_SECRET jti(unique id for logout revocation)
| Return field | Type | Description |
|---|---|---|
access_token | string | Signed JWT |
token_type | "Bearer" | Always Bearer |
expires_at | string | ISO-8601 expiry |
Throws if WebApp context is missing, user_id is empty, or WEBAPP_JWT_SECRET is unset.
const issued = jwt.issueWebappAccess({
user_id: endUserId,
email: endEmail,
role: "member",
expires_in: "15m"
});
Login stays on the JSON WebApp POST (published page POST), not /api/*.
For cookie or both, returning access_token still triggers Set-Cookie via the runtime. For bearer, the token stays in the JSON body only.
Recommended client storage for Bearer tokens: in-memory. localStorage is readable by any XSS on the page.
Later requests:
POST /{webapp_id}
Authorization: Bearer <jwt>
Content-Type: application/json
Runtime verification and process_input.auth
Before the ProcessFlow runs, the published WebApp runtime:
- Reads Bearer (
Authorization) and/ortf_sessioncookie perauth_transport. - Verifies JWT-shaped
webapp_accesstokens (signature, expiry, audience/webapp_id, tenant, revocation). - On failure with JWT present: returns 401 and does not run the process.
- On success: injects identity into process input.
Injected fields:
| Field | Shape | When |
|---|---|---|
process_input.auth_token | string | Raw presented token |
process_input.auth | { user_id, email, role, webapp_id, type } | Valid webapp_access JWT |
type is "webapp_access". Claims match what jwt.issueWebappAccess minted for this WebApp.
On /api/* for api_router processes, process_input.token is still set for compatibility. Query ?token= is not used for webapp_access. It remains only when the api_router process config token_types includes document_review.
Optional in-step check (defense in depth; runtime already 401s when auth_require is true and the token is missing/invalid):
const auth = process_input.auth;
if (!auth || !auth.user_id) {
return {
success: false,
error: { code: "UNAUTHORIZED", message: "Authentication required" }
};
}
// Optional app-level authorization
if (auth.role !== "tenant_admin") {
return {
success: false,
error: { code: "FORBIDDEN", message: "Forbidden" }
};
}
// Business logic runs as webapp_user_id; use auth.user_id for end-user attribution.
const userId = String(auth.user_id);
You normally do not call jwt.verify yourself for the published WebApp gate — the runtime already verified. Use jwt.verify only for advanced cases (for example verifying a token passed as a field inside body data). Prefer process_input.auth for identity.
Require authentication
auth_require (default false) returns 401 on POST and /api/* when no token is present.
Keep auth_require off on login WebApps that issue tokens. Turn it on for APIs and pages that assume the user is already signed in.
Invalid, expired, revoked, or wrong-webapp JWTs also return 401 and the process does not run. Opaque (non-JWT) tf_session values still pass through in cookie mode for existing apps. Opaque Bearer is not supported.
A webapp_access token cannot call product /api/v1/* routes. Product guards reject type: webapp_access. A token issued for WebApp A cannot be used on WebApp B.
Protected data ProcessFlow checklist
- WebApp (or sibling):
auth_require: true, sameauth_transportas login. - Step starts by reading
process_input.auth(see snippet above). - Perform work as
webapp_user_id(tf.datapool,tf.api, integrations, …). That service account may read and write DataPool data but cannot permanently delete rows (data.deleteis not granted). Soft-delete with an update (for example setis_deleted/deleted_at); use a separate scheduled or event-triggered process for hard deletes — see DataPool user guide and Process sandboxtfAPI. - Return business fields under the normal process success envelope; the HTTP POST wrapper puts them at
result.output_data— see WebApp–ProcessFlow integration.
Logout
- Bearer: drop the in-memory token. Optionally return
clear_auth_cookie: trueif you also used cookies. - Cookie / both: return
clear_auth_cookie: truefrom the logout process. The runtime clearstf_sessionand revokes the presented JWTjtiwhen present.
Passwords and tokens in logs
| Data | Store in the database | Logs / execution history / debug |
|---|---|---|
User-submitted password (including passwd, current_password, new_password) | Never in clear text. Hash with a one-way password hash inside the snippet if you persist users. | Never in clear text. Always "****". |
access_token / session_token / refresh_token / auth_token / Authorization | Do not store full JWTs in WebAppExecutionLogs or process history. App-owned session tables may store hashes or jti. | Masked only (prefix/suffix). |
| Email / username | Allowed | Allowed |
Do not tenantDb.insert raw passwords. Do not console.log login payloads. Compare hashes; never log process_input.password.
Related guides
- WebApps: admin-only access and DataPool viewers — restrict a published WebApp to
tenant_admin(or similar) withwebapp_accessand ProcessFlow role checks - WebApps User Guide
- WebApps API Documentation
- WebApp Functions Guide
- WebApps Process Response Reference
- Process sandbox
tfAPI —jwt.issueWebappAccess/jwt.verify - AI adoption advisor — JWT engagement app using this login pattern