Skip to main content

Run a complete sign-in application

Run one small website with sign-in → consent → callback → protected page → logout. The download includes Node.js, Next.js and Cloudflare Workers adapters sharing the same OAuth/OIDC implementation. It uses the maintained openid-client library, validates ID-token signatures against JWKS, and checks issuer, audience, expiry, state, nonce and S256 PKCE before creating an application session.

Choose the application you are building​

ApplicationClient recommendationStart here
Server-rendered website: Node.js, Next.js or WorkersPublic with PKCE for this starter, or confidential with a server-side secretContinue below
React / browser-only SPAPublic with PKCE; a browser cannot keep a client secretUse a browser OIDC library and the OAuth flow; this starter can serve as your server-side session layer
Mobile appPublic with PKCE and a registered app callbackFollow the OAuth flow with your platform's OIDC library
Backend service without a person signing inConfidential, client credentials grantMachine-to-machine integration

In the dashboard's Applications form, What are you building? selects recommended client settings. A website hosted on Workers still has server-side code; it is different from a browser-only React app.

1. Register the application​

Complete account, workspace and application setup. For this starter, choose Public, enable authorization_code,refresh_token, choose response type code, and allow openid profile email write. SyAuth requests write during sign-in, so allow it even when your first test only displays the user's name.

Generate your starter configuration

Register this exact callback in SyAuth: http://127.0.0.1:3000/auth/callback

This starter supports a public client with S256 PKCE. A confidential client may also be used by setting its secret on the server.

APP_URL=http://127.0.0.1:3000
SYAUTH_ISSUER=https://api.syauth.com/e/v1
SYAUTH_CLIENT_ID=YOUR_PUBLIC_CLIENT_ID
SESSION_SECRET=REPLACE_WITH_YOUR_RANDOM_SECRET

Run npm start after completing the setup below.

The configuration stays in this browser. Keep client secrets and developer tokens out of this form.

Register the generated callback exactly, including scheme, hostname, port and /auth/callback. For local Node.js/Next.js this is http://127.0.0.1:3000/auth/callback. For local Workers it is http://127.0.0.1:8787/auth/callback. Your deployed website has a separate HTTPS callback, for example https://your-app.example/auth/callback.

This path is implemented by the downloaded starter. Registering a URL alone does not create a callback route in another application.

ValueWhere to find itWhere it belongs
Public Client IDApplication details, client_idSYAUTH_CLIENT_ID; this value is public
Client SecretConfidential client creation/reset onlyOptional SYAUTH_CLIENT_SECRET, on the server only
Developer API tokenDeveloper access tokensResource-management calls, not required by this sign-in starter
Session secretGenerate belowSESSION_SECRET, server only; identical on all replicas of this website

2. Download and configure​

Use Node.js 22.12 or later and npm. Download the complete starter, extract it, then open a terminal in the extracted syauth-sign-in-starter directory:

npm ci
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

Copy the generated random value into SESSION_SECRET. Copy .env.example to .env, then set APP_URL, SYAUTH_CLIENT_ID and the secret. Keep SYAUTH_ISSUER=https://api.syauth.com/e/v1 unless you intentionally use a different trusted issuer. The discovery URL is derived from that issuer; the returned issuer must match.

For a confidential client, also set SYAUTH_CLIENT_SECRET. The public client path needs no client secret. Never prefix secrets or API tokens with NEXT_PUBLIC_, and never commit .env, .env.local or .dev.vars.

3. Start your runtime​

Node.js​

npm start

Open http://127.0.0.1:3000. The adapter binds to loopback; deploy it behind your HTTPS reverse proxy and set APP_URL to the public HTTPS origin. Set PORT if the upstream listener needs a different port.

Next.js​

Copy the same values from .env into .env.local so Next.js loads them, then run:

npm run dev:next

Open http://127.0.0.1:3000. The catch-all Route Handler serves the starter pages. For deployment, run npm run build:next and use your normal Next.js hosting process. Set the environment variables in the hosting provider and register its HTTPS callback before testing.

Cloudflare Workers​

Edit wrangler.toml: set your Client ID and APP_URL=http://127.0.0.1:8787 for local testing. Create .dev.vars containing SESSION_SECRET=YOUR_GENERATED_SECRET and, only for a confidential client, SYAUTH_CLIENT_SECRET=YOUR_CLIENT_SECRET.

npm run dev:worker

Open the exact http://127.0.0.1:8787 address. For deployment, change APP_URL to your Worker/custom-domain HTTPS origin, register that callback, and set secrets using npx wrangler secret put SESSION_SECRET and, when required, npx wrangler secret put SYAUTH_CLIENT_SECRET. Publishing with npx wrangler deploy is a separate action you perform after configuration.

4. Verify the complete flow​

  1. Open the website and click Sign in. Start here for every attempt; do not paste an old authorization URL.
  2. Sign in as an application user in the registered client's workspace. This is separate from your dashboard account. Complete email verification if requested.
  3. Check the application and requested permissions on SyAuth's consent page, then approve. An auto-approved client may skip this screen.
  4. Return to the website's /auth/callback. The library checks state, exchanges the code with the original PKCE verifier, validates the signed ID token and creates an encrypted HttpOnly cookie.
  5. The Protected page displays the signed-in identity. A direct visit without a valid session redirects to sign-in.
  6. Click Sign out of this website. The POST is protected against cross-site requests, clears the application cookies, and returns home. Opening the protected page requires a new application login attempt.

Logout ends this website's session. It does not claim to end the separate SyAuth hosted-login session or all sessions on other websites. SyAuth may recognize an existing hosted session on your next login. This starter retains no access/refresh token after creating its application session; it does not implement API calls or token refresh. The encrypted session expires no later than the ID token and at most one hour after sign-in.

Troubleshooting​

What you seeAction
Redirect URI rejected before returningRegister the exact generated callback and start a new attempt. localhost and 127.0.0.1 are different hosts.
CLIENT_CONFIGURATIONCheck Client ID, public/confidential type and the server-side secret for a confidential client.
LOGIN_ATTEMPT_EXPIREDStart from this website's Sign in link. The original 10-minute attempt cookie is missing, expired or invalid.
OAUTH_VALIDATIONCheck callback registration, client settings and the configured issuer. Start a fresh attempt; a callback code is single-use. If it persists, report the diagnostic, runtime and time, without tokens or cookies.
APP_ORIGINSet APP_URL to the exact origin you opened; use HTTPS outside loopback.
LOGOUT_CSRFOpen the protected page and use its Sign out button from that same origin.
Local server cannot startCheck the configured port, required variables and secret length.

Verification and boundaries​

Run npm test for the shared flow and adapter checks, npm run test:node for the real Node HTTP adapter, and npm run test:worker for the real Workers runtime. Tests use an isolated identity-provider fixture with real RSA-signed tokens; they cover success, callback replay, cookie tampering, expiry, invalid state/nonce/issuer/audience/signature and logout protection. These tests do not certify your application's hosted configuration: perform the checklist above against your registered client after deployment.

The starter has no database and uses encrypted cookies. Clearing a cookie signs out that browser; it does not centrally revoke a previously copied cookie. Applications needing immediate administrative session revocation should replace the cookie session with a server-side session store. Keep your session secret stable across replicas and rotate it to invalidate all starter sessions.