Quickstart · Node
Run a server-rendered Node integration.
The tested Node example starts an authorization-code + PKCE transaction against the local fixture issuer, validates the callback on the server, creates a separate product session and completes RP-initiated logout. Every secret stays on the server.
1. Run the tested local quickstart
From the repository root, the harness starts a real local fixture issuer plus the accepted Node client on http://127.0.0.1:4311. It prints the exact issuer origin and environment names before serving the app.
npm run quickstart:node
# Expected output includes:
# Connectas node quickstart: http://127.0.0.1:4311
# Local fixture issuer: http://127.0.0.1:<fixture-port>
# Same integration path, automated:
npm run test:quickstart
npm run test:e2e -- --grep "executable .* quickstart"
Open the product URL, choose Sign in with the local fixture issuer, and confirm the signed-in subject. Then choose Sign out: the browser must reach the issuer end-session endpoint before the product shows a signed-out state.
The local fixture is a real HTTP discovery, JWKS, authorization-code, PKCE and end-session implementation with a synthetic subject. It is not a production client registration or a live customer identity.
2. Environment explanation
The accepted local values below are supplied by examples/quickstart/dev.mjs. Production uses the canonical issuer https://auth.connectas.me only after an approved application registration; never copy the loopback values into production.
# node local accepted values, printed by the harness
CONNECTAS_AUTH_ISSUER=http://127.0.0.1:<fixture-port>
CONNECTAS_OIDC_CLIENT_ID=connectas-quickstart-node
CONNECTAS_OIDC_CLIENT_SECRET_REF=env:QUICKSTART_CLIENT_SECRET
CONNECTAS_REDIRECT_URI=http://127.0.0.1:4311/auth/callback
CONNECTAS_PUBLIC_ORIGIN=http://127.0.0.1:4311
HOST=127.0.0.1
PORT=4311
| Environment name | Required | Local example | Purpose |
|---|---|---|---|
CONNECTAS_AUTH_ISSUER | Yes | http://127.0.0.1:<fixture-port> | Exact issuer origin. The local harness prints it. It must match discovery issuer exactly and must not contain a path, query or trailing slash. |
CONNECTAS_OIDC_CLIENT_ID | Yes | connectas-quickstart-node | Public client identifier. The local harness registers the Node or VLX accepted client shown on this page. |
CONNECTAS_OIDC_CLIENT_SECRET_REF | Yes | env:QUICKSTART_CLIENT_SECRET | Reference, not a secret value. The quickstart resolves env:NAME or file:/absolute/path on the server. |
CONNECTAS_REDIRECT_URI | Yes | http://127.0.0.1:4311/auth/callback | Exact registered callback. The callback must use /auth/callback and the same origin as CONNECTAS_PUBLIC_ORIGIN. |
CONNECTAS_PUBLIC_ORIGIN | Yes | http://127.0.0.1:4311 | Product origin used for same-origin logout checks and return URLs. Use https outside a loopback local fixture. |
HOST / PORT | Yes | 127.0.0.1 / 4311 | Local listen address and port. The accepted ports are 4311 for Node and 4312 for VLX. |
Secrets are references, not values. env:QUICKSTART_CLIENT_SECRET tells the sample to read the value from that environment variable; file:/absolute/path is also supported. The secret must never appear in HTML, browser JavaScript, logs or this repository.
3. Core server wiring
Use @velox/auth-oidc-client instead of building token, PKCE or callback verification by hand. This condensed panel shows the core calls used by the executable sample; the complete server, including cookie handling, logout CSRF and safe error pages, is examples/quickstart/node/server.mjs.
import {
MemoryRelyingPartyTransactionStore,
createConnectasClient
} from '@connectas/client';
import { loadQuickstartSettings } from './config.mjs';
const settings = await loadQuickstartSettings();
const client = createConnectasClient({
issuer: settings.issuer,
clientId: settings.clientId,
clientSecret: settings.clientSecret,
redirectUri: settings.redirectUri,
scopes: ['openid', 'profile', 'email'],
transactionStore: new MemoryRelyingPartyTransactionStore(),
allowInsecure: settings.allowInsecure
});
// GET /auth/login: keep the one-use transaction server-side.
const started = await client.begin({ returnTo: '/', browserBinding });
// Set browserBinding in an HttpOnly SameSite=Lax cookie scoped to /auth.
reply.redirect(started.url);
// GET /auth/callback: consume once and verify state, binding, PKCE,
// issuer, audience, nonce and signature before creating a product session.
const result = await client.complete({ state, code, browserBinding });
// Set a host-only HttpOnly product session cookie. Never send tokens to HTML.
reply.redirect('/');
// POST /auth/logout: verify same-origin + CSRF, delete the product session,
// then continue to the issuer's RP-initiated logout endpoint.
const logoutUrl = await client.endSessionUrl({
idTokenHint: session.idToken,
postLogoutRedirectUri: `${settings.publicOrigin}/`
});
reply.redirect(logoutUrl ?? '/');
// The complete executable server, including error pages and cleanup, is
// examples/quickstart/node/server.mjs.
4. Validate the callback
- Store the transaction server-side and consume it once; reject replay, expiry and a transaction from another client or issuer.
- Require the browser binding, state, nonce, issuer, audience, PKCE verifier and ID-token signature to match.
- Resolve an explicit organization, tenant and membership where your product needs authorization; never infer permission from an email address.
- Create a host-only
HttpOnly,SameSite=Laxproduct session cookie with a bounded lifetime. AddSecurewhen the product origin is HTTPS. - Redirect to an allowlisted product path, never a user-controlled URL. Keep the issuer ID token server-side for logout.
Wrong issuer, audience, state, nonce, PKCE verifier, expiry, replayed transaction, missing binding and missing membership must all fail closed. The sample returns a safe error code and never echoes the raw authorization code or token.
5. Generic hosted-product recipe
This is the published recipe for any server-rendered product that uses hosted login. The executable consumer is examples/hosted-product/run.mjs; it starts a generic non-Sposato product, a local fixture issuer and a logging reverse proxy, and proves the complete path without a browser. The product name and permissions are configuration, not shared-code branches.
node examples/hosted-product/run.mjs
npm run test:hosted-product
# Expected markers include:
# authorize URL, Basic exchange, strict claims and local profile/permissions OK
# state-checked denial, replay and unknown state rejected with zero token exchanges
# durable logout transaction survives product restart and still rejects replay
# reverse-proxy and product logs redact code, state and id_token_hint
import {
MemoryRelyingPartyTransactionStore,
createConnectasClient
} from '@connectas/client';
import {
createFileLogoutTransactionStore,
randomUrlSafe,
redactOidcUrlForLog,
sha256Hex
} from '@velox/auth-oidc-client';
const client = createConnectasClient({
issuer: 'https://auth.connectas.me',
clientId: 'northwind-reports',
clientSecret: resolveSecret('env:NORTHWIND_CLIENT_SECRET'),
redirectUri: 'https://app.example.test/auth/callback',
transactionStore: new MemoryRelyingPartyTransactionStore()
});
// GET /auth/login: only a local same-origin return path is stored.
const returnTo = safeReturnPath(request.query.returnTo) ?? '/';
const browserBinding = randomUrlSafe(24);
const started = await client.begin({ returnTo, browserBinding });
// Set browserBinding in an HttpOnly SameSite=Lax cookie scoped to /auth.
reply.redirect(started.url);
// GET /auth/callback: consumes state before denial or code handling and
// verifies issuer, audience, nonce, PKCE and signature.
const result = await client.complete({ state, code, browserBinding });
const profile = profiles.get({ issuer: result.issuer, subject: result.subject });
sessions.create({ profile, idToken: result.idToken });
// POST /auth/logout: same-origin + CSRF, delete the product session, then
// continue to the discovered issuer end-session endpoint.
const endSessionUrl = await client.endSessionUrl({
idTokenHint: session.idToken,
postLogoutRedirectUri: `${publicOrigin}/auth/logout/callback`,
state
});
await logoutTransactions.create({
stateHash: sha256Hex(state),
issuer,
clientId,
browserBindingHash: sha256Hex(binding),
returnUri: '/'
});
log(redactOidcUrlForLog(endSessionUrl)); // never log the raw id_token_hint
reply.redirect(endSessionUrl);
// The complete executable server, denial case, local profile store and
// logging reverse proxy are in examples/hosted-product/.
Authorize URL and Basic token exchange
Redirect the browser to the discovery authorization_endpoint with response_type=code, client_id, the exact registered redirect_uri, scope, one-use state, nonce, code_challenge and code_challenge_method=S256. The code_verifier and client secret stay server-side. Exchange the code with grant_type=authorization_code and client_secret_basic; the Connectas client does this by default.
Strict callback and denial rules
Consume the browser-bound state transaction before interpreting either code or error. Reject wrong issuer, audience, nonce, expiry, PKCE verifier, signature, browser binding and replay. A denial burns the transaction, creates no product session and performs zero token exchanges. Unknown or expired state must fail closed; never reuse a callback URL.
Local return paths, profile and permissions
Only a local same-origin path may be stored as returnTo; absolute, protocol-relative, backslash and control-character paths are dropped. Map the verified (issuer, subject) to a local profile and permission record. ID-token claims are identity evidence, not product roles: an admin claim does not create a local permission unless the product's own store grants it.
Durable standards logout
Logout uses the discovered end_session_endpoint, the server-retained id_token_hint, the exact registered post-logout URI and a one-use state. Delete the product session before redirecting. Persist only sha256(state) with the exact issuer, client, browser binding and fixed return URI; consume it atomically and retain the consumed marker until expiry so a replay or product restart still fails closed. An issuer outage must not restore the product session.
Reverse-proxy and browser boundaries
A reverse proxy must not log the raw request target. Prefer disabling query-string logging; when a target is needed, use redactOidcUrlForLog() from @velox/auth-oidc-client. It masks code, state, nonce, id_token_hint, tokens and direct identity hints while keeping the route and safe parameters. The browser receives only an opaque HttpOnly product-session cookie: no access token, refresh token, provider token, authorization code or private-control secret is rendered in HTML, browser storage or logs.
6. Logout and callback troubleshooting
Deleting the product cookie is not complete logout. The tested sample clears its own session and then redirects to the issuer's end_session_endpoint from client.endSessionUrl(...) with an ID-token hint and an allowlisted post-logout origin. The local fixture records that request before returning fixture end session.
Callback failures and logout failures should be diagnosed without logging the authorization code, state, verifier, ID token or client secret. Use the platform error code and a redacted correlation ID.
| Symptom | Likely cause | Next action |
|---|---|---|
| Issuer rejects the request with an invalid client or redirect URI | CONNECTAS_REDIRECT_URI does not exactly equal the registered callback, or the client ID belongs to another registration. | Use the exact origin, path and port from the environment table. Do not add a trailing slash, query or fragment. |
| Callback shows invalid_state or the transaction cannot be found | The one-use transaction was already consumed, expired, or lost because the product restarted. The in-memory store does not survive a restart. | Start sign-in again in the same browser. In a deployed product, use a durable one-use transaction store and never replay a callback URL. |
| Callback shows browser_binding_mismatch | The callback arrived in a different browser/tab without the HttpOnly binding cookie, or the cookie was blocked or cleared. | Keep the binding cookie on /auth, allow same-site top-level redirects, and never move the callback URL to another browser. |
| Could not start sign-in or discovery failed | The issuer origin is wrong, the local fixture is not running, or discovery is unreachable from the server. | Start the matching quickstart command, use the printed issuer origin, and check the exact /.well-known/openid-configuration endpoint. |
| Token exchange failed | The resolved client secret does not match the registered client, or the secret reference is unset. | Check the env: or file: reference on the server. Never put a client secret in browser code, HTML, logs or this repository. |
| Sign out returns to the product but the issuer session still exists | Only the product cookie was deleted. Local cookie deletion is not complete logout. | Clear the product session and redirect to the issuer end_session_endpoint from client.endSessionUrl(...). Confirm the issuer receives the request. |
| Sign-in works but product records are missing or empty | The issuer is not your application database. Identity claims do not create product records. | Create or read product data in your own product database keyed by the stable issuer + subject pair. Never read product records from the issuer database. |
| Clicking Sign out appears to do nothing and the browser cancels the POST | A Content-Security-Policy form-action directive allows only the product origin while the logout form redirects to the issuer origin. | Allow the exact issuer origin in form-action, or complete logout with a server-checked fetch followed by a client navigation. Keep the CSRF and same-origin checks. |
| API returns 401 token audience mismatch | An ID token or a token minted for another API is being used as a bearer token, or the API audience was not requested through an explicit client grant. | Validate signature, exact issuer, audience, expiry and tenant at the resource API. Use the ID token only for login; request an access token for the exact registered API audience. |
| Token endpoint returns invalid_grant after a correct-looking callback | The PKCE verifier, redirect URI or one-use transaction no longer matches the authorization request, or the callback was replayed. | Keep the verifier and transaction server-side, consume exactly once and send the same exact redirect URI used to start the flow. Never disable PKCE to work around the error. |
| Browser blocks the token response with a CORS error | A confidential server-rendered client is calling the token endpoint from browser JavaScript, or a public SPA origin is not the exact registered origin. | Keep confidential token exchange on the server. For a public SPA, register the exact origin and use authorization code + PKCE with token_endpoint_auth_method=none. |
| User appears signed in but the product session is missing or expired | The issuer session and the product session are separate. A valid issuer cookie does not create a product cookie, and the product may have expired or restarted. | Create an opaque HttpOnly product session only after a verified callback. On expiry or restart, start a new authorization request; do not infer a product session from the issuer cookie. |
| Sign-in fails at a provider or MFA step | The provider returned access_denied/login_required, the factor challenge expired, or the requested method is not enabled for this tenant/client. | Consume the state transaction and show a safe denial message with a correlation ID. Start a new attempt instead of replaying the old callback, and check the tenant method catalog rather than only the provider credentials. |
| Signed in but the product shows no permissions | The product has no local profile/membership record for the verified (issuer, subject) pair. Token claims are identity evidence, not product roles. | Create or read the product permission record in its own database keyed by issuer + subject. Do not grant a role from an email address or an arbitrary ID-token claim. |
| Authorization code or logout token appears in reverse-proxy logs | The access-log format records the raw request target, including code/state/id_token_hint query values. | Disable query-string logging or log redactOidcUrlForLog(request.url) from @velox/auth-oidc-client. Never copy a raw callback URL into an issue tracker, chat or audit row. |
7. Integration checklist
- Exact callback and post-logout allowlists; no open redirect.
- No token, code, verifier or secret in browser storage, HTML or logs.
- Tenant-scoped membership checks with a foreign-resource denial case.
- Health/readiness and a redacted correlation ID for failures.
- No success page until the issuer round trip and required product checks actually complete.
- Durable one-use transaction and session stores before a deployed product; the sample uses in-memory stores.
8. Separate product databases
The issuer database and the product database are separate systems. Connectas stores authentication identities, provider connections and issuer sessions; it does not become the application database for product records, and Connectas does not host customer applications. The quickstart keeps its product session in memory only for local demonstration.
| Store | Owns |
|---|---|
| Connectas public site | Renders product content and stores contact requests in its configured local acknowledgement store. It does not open an auth database or verify an identity directly. |
| auth.connectas.me | Owns hosted authentication, provider composition and the private control service. Product membership and console authorization remain separate decisions. |
| identity runtime | Owns reusable identity, session, OAuth/OIDC, passkey, authorization and persistence contracts. Connectas consumes these; it does not duplicate them. |
| Customer application | Owns its own product data and server session. Connectas does not host customer applications or become their application database. |
Key product records by the stable issuer + subject pair. Do not join on email or domain, and do not read product records from the issuer database. Each product/database pair needs its own scoped credentials and backup/restore ownership.
Limits
This is local fixture evidence, not production acceptance. The sample has no production client registration, durable transaction/session store, customer provisioning or live issuer round trip. The console composition has separate fixture-backed evidence; do not treat this quickstart as proof of a live provider, MFA or passkey policy.