Skip to content
Udibo

Move an in-memory app from @node-oauth/oauth2-server 5.x

This example starts from the Node OAuth project’s Express authorization-code provider. It loads users and clients from seed.js and keeps issued codes and tokens in process memory. You can replace the library while you still run the provider (Phase A). Moving sign-in and users to Udibo Identity is a separate decision (Phase B). In both cutovers, plan for users to sign in again when the old process stops. Worked in-memory example

Step tagWhat changes in the appEvidence
step-0-upstreamThe runnable Express provider uses @node-oauth/oauth2-server 5.x behind @node-oauth/express-oauth-server 4.x.Baseline behaviour tests
step-1-udibo-packageThe app uses @udibo/oauth2 0.46.0 to issue tokens and protect its API. Its stores still live in the process.Library and test changes
step-2-udibo-idpThe app signs in through the configured provider and checks JWT access tokens at /protected.Client and API changes
step-3-user-importA command exports user records from the seed for import. Client registration and cutover are deployment steps.Exporter and tests

Compare the first two transitions on GitHub. Library replacement · Issuer change

To compare the export code and tests in your checkout, run git diff step-2-udibo-idp step-3-user-import -- scripts test.

Phase A — coordinate the PKCE cutover

Step 0 requires state, ignores the PKCE challenge and rejects a code exchange that includes the verifier. Step 1 requires state and S256 PKCE. Prepare clients to generate a challenge and retain its verifier. Coordinate the switch so clients send that verifier at exchange when step 1 takes over. Start a fresh sign-in if an exchange straddles the switch and fails. Keep the seeded public client secretless. The two confidential clients also authenticate at exchange with their respective secrets. Cutover sequence

Step 1 offers authorization code and refresh. The original seed did not grant the password or client-credentials grant to any client. The replacement changes the error for those requests and grants read when scope is omitted. Check client error handling as well as successful sign-in, refresh and access to /protected. Stopping step 0 discards its outstanding codes and tokens. Rolling back to the old server also requires returning clients to the old exchange behaviour and signing in again. Protocol changes covered by tests

Phase B — point the app at the destination

First rehearse on synthetic users. In a checkout of step-3-user-import, use Node.js 22.12 or later. Run the commands in a shell with AUTH_ISSUER unset. The suite then starts a local identity provider and exercises the app without a tenant or external database.

Shell
npm ci
npm test

For an interactive run, replace the SESSION_SECRET placeholder in your private environment file with a fresh random value before starting the app. For a hosted rehearsal, register the app as a confidential authorization-code client with an exact callback URL. Enable openid and profile, and configure JWT access tokens for the API’s audience. Set AUTH_ISSUER, AUTH_CLIENT_ID, AUTH_CLIENT_SECRET, AUTH_REDIRECT_URI and AUTH_AUDIENCE for the destination. Check sign-in, the signed-in page at /home and API access at /protected. Local setup · Tenant registration

Export the users and verify the import

The process loads its users from the seed. Step 3 therefore exports the seed, including when the old server is stopped. If your deployment loads accounts from another source, identify the authoritative records first. Freeze account and password changes through cutover or arrange reconciliation. From the example checkout, set export_dir to a private directory outside the repository. Create the directory first, exclude it from automatic backups and sync, and choose an unused filename.

Shell
npm run export:users -- "${export_dir:?}/users.ndjson"

Each record has the username and a legacyCredential bcrypt hash generated from the source password, at cost 12 by default. The exporter reports how many passwords exceed bcrypt’s 72-byte input limit. Resolve those cases before relying on password continuity. Protect the file and arrange a secure handoff and dry run with Udibo. Reconcile imported, skipped and refused records. After verifying the import, delete the export file and any copies made during handoff. Re-import skips an already-taken username and cannot update its password. Verify the source ID to destination subject mapping before attaching app data. These records carry no email, so include account recovery in your rehearsal. Import procedure

Switch the clients together

Register the destination clients before stopping step 1. Each gets a new ID and the grants and redirect URIs it needs. Provision a new secret only for confidential clients. Update discovery endpoints and issuer checks, and deploy the settings together with the switch.

The old access and refresh tokens disappear when the step-1 process exits. A new API process cannot recover them from a database. If clients must move at different times, the documented alternative requires both deployments to keep serving their respective clients on separate origins. Rehearse that arrangement yourself. After verifying imported sign-in and moving the last dependent client, stop the old process and retire deployed copies of the plaintext seed under your retention policy. The example repository keeps its synthetic seed. Client switch-over

What was verified

  • On Node 22 and 24, CI ran the documented export command and checked both seed users and the default bcrypt records. This command coverage landed after the step-3 tag. There is no users table to retire in this example. Command CI

  • The November 30 hosted development-tenant workflow ran the suite, including sign-in and protected API access with a preconfigured user. Forty-three tests passed. Three skipped because they needed another user, a step-1 client registration or a shorter token lifetime. Hosted run

  • On November 6, one manual rehearsal imported two synthetic users on a local Udibo development server and observed their export-generated bcrypt hashes upgrade on first sign-in. Rehearse the hosted handoff and an imported account’s first sign-in separately. Manual rehearsal record

Last verified 2026-11-30.

View Markdown