This repository takes the authorization code provider from
node-oauth/node-oauth2-server-examples,
which runs @node-oauth/oauth2-server
5.x through
@node-oauth/express-oauth-server
4.x, and moves it to @udibo/oauth2 and
then to Udibo's hosted identity service, one tagged step at a time. Each step
is a commit range you can read on its own; compare two tags to see exactly what
that step changes.
Use the tags to inspect the code changes. Use this README on main for the corrected setup and cutover instructions.
| Tag | What the app runs on |
|---|---|
step-0-upstream |
The upstream example, fixed only as far as it needs to run |
step-1-udibo-package |
@udibo/oauth2 as its own authorization and resource server |
step-2-udibo-idp |
The app delegates sign-in to a configured issuer. Push CI uses a local provider. A separate workflow exercises a hosted Udibo development tenant. |
step-3-user-import |
Export the seeded users for import. The README walks through registering clients again and switching away from the in-memory server. |
step-4-password-migration |
Optional, instead of step 3's import: users imported without a hash, each password checked once at sign-in against an endpoint in front of seed.js |
The first commit copies the provider verbatim; UPSTREAM.md records its source and license. The provider is an authorization server and a resource server in one Express app, with an in-memory store. As published, it starts, but its authorization page fails to render. The commits after it change only what was needed, and each commit message lists its changes:
- Dependencies: unchanged.
npm ciinstalls upstream's lockfile:@node-oauth/express-oauth-server4.1.3 with@node-oauth/oauth2-server5.2.0, and Express 4.21.2. - Authorization page:
GET /oauth/authorizerenders a view the provider does not include. Upstream's client application carries that page and posts it to the provider; step 0 copies it intoviews/, posting to this server. - Tests: the app is exported, and listens on
PORTonly when run directly. The token and code lifetimes can be shortened from the environment, which the tests use. - Seed:
seed.jsholds synthetic clients and users, loaded into the in-memory store at startup. Upstream read one client and one user from environment variables. - Behaviour tests cover the upstream provider. Step 1 changes assertions for the new protocol. At step 2, tests exercise the app as a client and resource server.
Upstream's client application (authorization-code/client) is not included.
It is a separate app that collects the user's password on its own page and
posts it to the provider's /oauth/authorize, the same form the provider's
page now renders, so the provider can be exercised without it. The tests drive
the provider over HTTP instead.
These are the upstream example's behaviours, kept because the migration changes them:
-
Passwords and client secrets are stored and compared as plain text.
-
Everything lives in memory. Codes and tokens are lost when the process stops, and the app cannot run as more than one process.
-
Sign-in and consent are one form. The user types their password on every authorization; there is no sign-in session. The form carries no CSRF token.
-
PKCE does not work.
@node-oauth/oauth2-serversupports it, but the example's model does not store thecode_challenge. A code issued with a challenge can be exchanged without a verifier, and a client that sends the matchingcode_verifieris refused withinvalid_grant. -
An authorization request without
scopefails with a 503server_error, whose description is the model's internalTypeErrormessage. Requests that nameread,writeor both work. -
Refusals do not return to the client. A denial answers 403 with
{"error":"Access denied"}, and a wrong password 401. Other authorization errors answer with a JSON body and an error status (400 for most), asexpress-oauth-serverrenders them, rather than redirecting to the client. -
The authorization page shows the
client_idit is given before the client is checked; the check happens when the form is posted. -
CORS allows any origin on every route, including the token endpoint, because upstream's client exchanges the code from the browser.
-
A refresh token cannot be revoked. It works once: the refresh deletes the access token issued with it, and a second refresh is refused only because that access token is already gone. A refresh that asks for more scope than the grant is refused with
invalid_scope, and spends the refresh token all the same. There is no revocation endpoint. -
/protectedchecks no scope. Any valid access token reads it. -
The upstream lockfile carries known advisories.
npm auditreports 8 vulnerable packages (1 critical, 5 high, 2 moderate), checked 2026-11-05:Package Severity Advisories proxy-addrcritical GHSA-jqcg-44mw-7w3h body-parserhigh GHSA-v422-hmwv-36x6, GHSA-27r3-jxmh-p828; also depends on a vulnerable qsexpresshigh none of its own; depends on vulnerable body-parser,path-to-regexpandqspath-to-regexphigh GHSA-37ch-88jc-xwx2 minimatchhigh GHSA-3ppc-4f35-3m26, GHSA-7r86-cg39-jmmj, GHSA-23c5-xmqv-rm74 brace-expansionhigh GHSA-f886-m6hf-6m8v, GHSA-3jxr-9vmj-r5cp, GHSA-mh99-v99m-4gvg, GHSA-rgw5-rvv9-x895, GHSA-q2hr-2g5m-vwhr, GHSA-qhr7-859c-m2p7, GHSA-6j4f-fj2g-mc7p @node-oauth/oauth2-servermoderate GHSA-jhm7-29pj-4xvf (PKCE code_verifierformat not enforced, versions through 5.2.1)qsmoderate GHSA-w7fw-mjwx-w883, GHSA-6rw7-vpxm-498p, GHSA-q8mj-m7cp-5q26, GHSA-4mjr-xmp4-gh2g, GHSA-6pq8-jhm2-2vcw body-parserandexpressare the example's own dependencies, and@node-oauth/oauth2-servercomes with@node-oauth/express-oauth-server.proxy-addr,path-to-regexpandqscome in throughexpress(qsthroughbody-parsertoo), andminimatchandbrace-expansionthroughejs. The PKCE advisory concerns a code issued with a challenge, which this model never stores (above).
Step 0 also adds a weakness of its own: the seeded client secrets and user
passwords are fixed in seed.js, so anyone who has this repository can use
them.
Do not deploy step 0.
Step 1 keeps Express, the upstream file layout, the in-memory store, the seed
and the authorization page, and replaces @node-oauth/express-oauth-server
and @node-oauth/oauth2-server with
@udibo/oauth2:
index.jsmountsExpressAuthorizationServer'sroutes()at/oauth, before the body parsers, because the endpoints read the raw form themselves./protectedsits behindExpressResourceServer'sprotect().model.jsholds in-memory implementations of the package's service interfaces, over the maps indb.js.contract/stores.test.mjsruns them through the package's contract suites.seed.jsgainspublic-client, a client with no secret, so the tests can show what a public client may and may not do.
The app stays CommonJS. It loads the package, which is ESM only, with
require(), and that is why it needs Node.js 22.12 or later. Step 1 pins
@udibo/oauth2 0.46.0 and every other dependency to an exact version.
The clients keep the grants they had: the authorization code grant and
refresh. The server now offers only those two. The password and client
credentials grants, which step 0's oauth2-server understood but no client
was given, are now unknown to it: a request for either is refused with
unsupported_grant_type.
- Authorization code: PKCE (S256) is required of every client,
confidential ones included, and so is
state. A code is bound to its challenge, and an exchange must present the matchingcode_verifier. The two seeded confidential clients authenticate with their secrets. The seeded public client exchanges its code using PKCE without a client secret. - Refresh: every refresh rotates the refresh token. Presenting a token that rotation already replaced revokes the whole rotation family, so a stolen refresh token and the legitimate client cannot both keep refreshing. Presenting a code a second time revokes what it issued, and every rotation of it.
Sign-in and consent stay one form, as in step 0, but the decision is no longer posted to the authorization endpoint with the request's parameters.
GET /oauth/authorizechecks the client, the redirect URI,state,response_type, and the method and format of a PKCE challenge before it renders anything. A request without a challenge still gets the page, and is refused once the user has approved it. The page names the client and scope as the server reads them from the URL, and carries only an id for this request, which the session keeps with the exact authorize URL.- The form posts the id, the user's credentials and the button to
POST /oauth/authorize. A post whose id the session did not issue is refused with 400; that id is the form's CSRF token. A wrong password is refused with 401, as in step 0. - An approval starts a new session, recording the user and the decision, and sends the browser back to the authorize URL with a 303. A denial does the same without a user.
- On that second visit,
authenticateUserspends the decision if it is for that exact URL, and the server redirects to the client with a code, or witherror=access_denied. Any other request finds no decision and gets the page. Since the user has just typed their password, it reports a fresh sign-in (reauthenticated, withauth_timeandamr: ["pwd"]), andhandleConsentapproves what the form approved.
The decision is never read from the authorize URL's query, because the client
builds that URL. Sessions use express-session with memorystore, behind an
HttpOnly, SameSite=Lax cookie that expires after SIGN_IN_LIFETIME seconds
(ten minutes by default); the store drops expired sessions every minute.
Nothing else is kept in them: the user still types their password on every
authorization.
- Errors return to the client. Once the server has checked the redirect
URI, an authorization error redirects to it with
error,stateandiss(RFC 9207), as RFC 6749 §4.1.2.1 specifies. An unknown client or an unregistered redirect URI is still answered on this server, with 401invalid_clientorunauthorized_client, and never redirected. prompt=login,prompt=consentandmax_ageare honoured, since every approval takes the password and the consent.prompt=noneanswerslogin_required, because there is no sign-in to reuse.- A request without
scopegetsread(RFC 6749 §3.3), instead of failing with a 503. - A refresh that asks for more scope is refused without spending the refresh token.
- A code exchange that authenticates its client and then fails spends the code, so a code presented by another client, with the wrong verifier or with the wrong redirect URI cannot be tried again. A request whose client fails to authenticate leaves the code as it was.
- Revocation (
POST /oauth/revoke, RFC 7009) and introspection (POST /oauth/introspect, RFC 7662) are new, and so is the metadata document at/.well-known/oauth-authorization-server. A client can revoke its own tokens. Introspection returns details to an authenticated confidential client asking about its own token. Other authenticated callers get an inactive result. Invalid client authentication fails before this policy runs. - The token endpoint answers 401
invalid_clientfor a code or refresh token issued to another client. Step 0 answered 400invalid_grant, which is what RFC 6749 §5.2 specifies; this is filed as udibo/oauth2#179.
Everything step 0 holds is in memory, so stopping it ends every code and
token, as any restart of step 0 does. There is nothing to migrate, but PKCE
cannot be switched on from one side alone. Step 0 ignores a code_challenge,
but refuses a code exchange that carries a code_verifier with
invalid_grant; step 1 refuses an exchange without one.
- Before the cutover, every client sends
state(step 0 already requires it) and an S256code_challengeon/oauth/authorize, keeping the verifier. It does not send the verifier yet. - Coordinate the client and server cutover. When step 1 starts, send the stored verifier with each code exchange. If a sign-in crosses the switch and the exchange fails, start a fresh sign-in.
- Stop step 0 and start step 1, with
ISSUERset to the site's origin andSESSION_SECRETto a long random value. - Users sign in again the next time a client asks them to. A sign-in in progress at the switch fails at the code exchange, and the user starts again. Client ids and secrets are unchanged.
To roll back, stop step 1 and start step 0, and stop sending the verifier; the tokens step 1 issued are lost the same way.
Each method of step 0's model, and what does its job in step 1. The token
methods live on TokenService, which extends AbstractTokenService. The code
methods live on AuthorizationCodeService, which extends
AbstractAuthorizationCodeService. The client methods live on
ClientService, which implements ClientServiceInterface.
@node-oauth/oauth2-server 5.x model method |
@udibo/oauth2 equivalent |
Notes |
|---|---|---|
getAccessToken(accessToken) |
TokenReaderInterface.getToken(accessToken) |
What protect() calls. Returns undefined for a revoked token. The resource server checks the expiry itself. |
getClient(clientId, clientSecret) |
ClientServiceInterface.get(id) and getAuthenticated(id, secret) |
One method became two: get looks up a client with no credential, as /authorize does. getAuthenticated checks one: a confidential client only with its correct secret, compared in constant time, and a public client only when it presents none. |
getUser(username, password) |
No equivalent | Only the password grant calls it. The authorization form uses UserService.getAuthenticated, and authenticateUser uses its get(id). |
getUserFromClient(client) |
ClientServiceInterface.getUser(client) |
Only client credentials calls it, which step 1 does not offer. It returns the user a client acts for, if any; the seeded clients have none. |
saveToken(token, client, user) |
save(token), exchangeCode(code, token), rotate(current, next) |
The code grant calls exchangeCode, which claims the code and stores the token in one step. The refresh grant calls rotate. save stores any other first issuance. |
getRefreshToken(refreshToken) |
getRefreshToken(refreshToken) |
Returns live tokens only, with familyId. Revoked and rotated-out tokens come from getRevokedRefreshToken. |
revokeToken(token) |
rotate(current, next) for a refresh, and revoke(token, hint) for revocation |
oauth2-server called revokeToken to spend the old refresh token before saving the new one, and step 0's deleted only the access token. rotate spends the old pair and stores the new one in one step, holding a lock on the rotation family. revoke serves POST /oauth/revoke, which oauth2-server 5.x does not have. |
saveAuthorizationCode(code, client, user) |
AuthorizationCodeServiceInterface.save(authorizationCode) |
Also stores the PKCE challenge and method, which step 0's model dropped. |
getAuthorizationCode(authorizationCode) |
get(code) |
|
revokeAuthorizationCode(code) |
revoke(code), or exchangeCode on the token service |
It must answer true only for the call that removed a live code. |
validateScope(user, client, scope) |
acceptedScope(client, user, scope) |
Both restrict scopes to read and write. An omitted scope fails at step 0 and defaults to read at step 1. The argument order and scope representation also change. |
verifyScope(accessToken, scope) |
protect(requiredScope) or requireScope(scope) |
Scope is checked in middleware, not in the store. /protected still requires none. |
generateAccessToken, generateRefreshToken, generateAuthorizationCode |
generateAccessToken, generateRefreshToken, generateCode |
Kept, so tokens and codes have step 0's hex format. |
| — | revokeCode(code, client, codeVerifierHash) |
New. When a spent code is presented again, it revokes what the code issued, and every rotation of it (RFC 6819 §4.4.1.1). It does so only for the client the code was issued to. |
| — | getRevokedRefreshToken(refreshToken) and revokeFamily(familyId) |
New. Together they turn on refresh-token reuse detection. |
Step 1 adapts the behaviour suite to the replacement server. The table lists the changed expectations.
| Test | Change | Why |
|---|---|---|
| Every authorization request and code exchange | Carries an S256 code_challenge, and the exchange its code_verifier. |
PKCE is required. |
| The form submission | Keeps the session cookie, posts the page's request id, and follows the 303 back to the authorize URL. | The decision is recorded in the session, not posted to the authorization endpoint with the request. |
| Renders a form carrying the authorization request | The form carries only the request's id. | Same. |
| Escapes every request value it echoes | Checks the scope. The page still shows the client id, but only one the server has found, read from the URL as the server reads it; an unknown client is refused before the page renders. | The client is checked before the page renders. |
| Redirects to the client with a code and its state | Also checks the callback's iss. |
RFC 9207 issuer identification. |
| Issues no code when the user denies access | Redirects to the client with error=access_denied instead of answering 403. |
RFC 6749 §4.1.2.1. |
| Refuses a request without state; a scope outside read and write; a response type other than code | Redirect to the client with the error instead of answering 400. | Same. |
| Refuses an unregistered or another client's redirect URI; an unknown client | 401 unauthorized_client or invalid_client instead of 400 invalid_client. Still not redirected. |
The package's error codes. |
| Fails a request without a scope as a server error | Now grants read. |
A default scope. |
| Refuses a code exchanged with a different redirect URI, or without one | invalid_grant instead of invalid_request. |
RFC 6749 §5.2. |
| Refuses a code exchanged by another client | 401 invalid_client instead of 400 invalid_grant, and the code is spent. |
The package's behaviour, filed as udibo/oauth2#179. |
| Refuses a client that sends no secret | 401 instead of 400. | A confidential client failed to authenticate. |
| Refuses the password and client credentials grants | unsupported_grant_type instead of unauthorized_client. |
The server offers neither. |
| Does not bind a code to its challenge; refuses the matching verifier | Replaced by tests that PKCE is required and binds the code. | The PKCE advisory step 0 kept is fixed. |
| Refuses a refresh that asks for more scope, and spends the refresh token | The refresh token still works afterwards. | Refusal no longer spends it. |
| Refuses a refresh token presented by another client | 401 invalid_client instead of 400 invalid_grant. |
udibo/oauth2#179. |
The tests added in step 1 cover the form's request id and session, a query
split to show one client and grant another, prompt and max_age, the
sign-in lifetime, PKCE, replay of codes and refresh tokens, revocation,
introspection (a public client included) and metadata.
The eight advisories step 0's lockfile carried leave with its dependencies:
npm audit reports none at step 1 (checked 2026-11-05). Step 1 takes Express
4.22.3 and its patched proxy-addr, body-parser 1.20.9 and EJS 5.0.2, and
drops the @node-oauth packages, PKCE advisory included. What remains:
- Plain-text passwords and client secrets, in
seed.jsand in memory, until step 3. - Everything lives in memory, sessions included. A restart ends every
sign-in and token, and the app cannot run as more than one process.
Pending sign-ins expire after
SIGN_IN_LIFETIME, but nothing caps how many a client can start within it. - CORS allows any origin on every route, as in step 0.
/protectedchecks no scope, as in step 0.- The session cookie is not
Secure, so that it works onhttp://localhost. Behind HTTPS it should be.
Do not deploy step 1 without fixing those.
Check out step-1-udibo-package to run it.
Requirements: Node.js 22.12 or later.
npm ci
npm start # http://localhost:8080Set these in the environment or a .env file:
| Variable | Default | What it is |
|---|---|---|
PORT |
8080 |
Where the server listens |
ISSUER |
http://localhost:<PORT> |
The server's origin, sent as iss and in the metadata |
SESSION_SECRET |
a fixed development value | Signs the session cookie; set a long random value anywhere but your own machine |
SIGN_IN_LIFETIME |
600 |
Seconds a sign-in may stay pending on the authorization page |
The seed has three clients and two users:
| Client | Secret | Redirect URI |
|---|---|---|
example-client |
example-secret |
http://localhost:3000/callback |
other-client |
other-secret |
http://localhost:3002/callback |
public-client |
none (public) | http://localhost:3004/callback |
| User | Password |
|---|---|
alice |
alice-password |
bob |
bob-password |
Open
http://localhost:8080/oauth/authorize?response_type=code&client_id=example-client&redirect_uri=http://localhost:3000/callback&scope=read%20write&state=xyz&code_challenge=Ln4yqz2itBVun9P25eDRSlfVcDC1DaQVBlEXDTxFseo&code_challenge_method=S256,
sign in as alice / alice-password, and allow access. The browser lands on
the callback URL with a code; nothing needs to listen there. The challenge
is the S256 digest of the verifier below; a real client makes a new verifier
for every request. Exchange the code, with its verifier, within five
minutes. Set the shell variable CODE to the code from that callback.
curl -u example-client:example-secret \
-d grant_type=authorization_code --data-urlencode "code=$CODE" \
-d redirect_uri=http://localhost:3000/callback \
-d code_verifier=g1jRBkBesgn9WYlP-TmBFqB7AwiHTjtIpvuxpfWWWfQ \
http://localhost:8080/oauth/tokenThen call GET /protected with Authorization: Bearer <access_token>.
Exchange the refresh token with
grant_type=refresh_token&refresh_token=<refresh_token> and the same client
credentials; each refresh returns a new refresh token, and the old one stops
working. POST /oauth/revoke with token=<token> and the same credentials
revokes either token. GET /public needs no token.
ACCESS_TOKEN_LIFETIME, REFRESH_TOKEN_LIFETIME and
AUTHORIZATION_CODE_LIFETIME (seconds) default to one hour, two weeks and five
minutes.
Step 2 hands authorization to an identity provider. The app stops issuing tokens and becomes two things:
- An OAuth client.
GET /loginsends the browser to the provider's authorization endpoint with the authorization code grant, a PKCE (S256) challenge and astate.GET /callbackchecks the response'siss(RFC 9207), exchanges the code with the client's secret, reads the user from the provider's userinfo endpoint and starts a new session.POST /logoutends it.DirectClientfrom@udibo/oauth2/clientdoes the protocol work. - A resource server.
/protectedstays behindExpressResourceServer'sprotect(), now with aJwksTokenReader. It verifies the provider's JWT access tokens (RFC 9068) against the provider's published keys and accepts only tokens issued for this API's audience. No network call is made per request once the keys are cached. It answers as before, naming the user, or the machine client when the token has no user.
What goes: the /oauth routes and the metadata document, the authorization
page and its form route, model.js and db.js, the contract suite that
tested them, body-parser and dotenv (npm start reads .env with
Node's --env-file-if-exists). /public and /protected keep their
answers, and /home is the page a signed-in user lands on.
seed.js stays as step 1 left it. The app no longer reads it, but its users
are what step 3 imports into Udibo.
The same code runs against the local identity provider and against a Udibo tenant. Only the environment changes.
The app reads these from the environment. npm start also reads a .env
file; copy .env.example, which points at the local provider,
and keep .env out of version control. Step 1's ISSUER, SIGN_IN_LIFETIME
and token lifetimes are gone: the provider sets them.
| Variable | What it is |
|---|---|
AUTH_ISSUER |
The identity provider's issuer URL. The app discovers every endpoint from it. |
AUTH_CLIENT_ID |
The app's client id at the provider. |
AUTH_CLIENT_SECRET |
The app's client secret. The app is a confidential client, so it keeps the secret on the server. |
AUTH_REDIRECT_URI |
The callback URL registered for the client, exactly: https://<your app>/callback. |
AUTH_AUDIENCE |
The audience the provider puts on access tokens for this API. /protected refuses a token for any other. |
AUTH_SCOPE |
Optional. The scope the app signs in with; openid profile by default. |
AUTH_POST_LOGOUT_REDIRECT_URI |
Optional. Where the provider sends the browser after sign-out, when it supports that. It must be registered for the client. |
SESSION_SECRET |
Required; the app will not start without it, or with the placeholder in .env.example. Signs the session cookie. Long and random, and different in every environment. |
SESSION_TTL_SECONDS |
Optional. How long a signed-in session lasts; eight hours by default. See Sessions. |
TRUST_PROXY |
Optional. Set it when a proxy in front of the app terminates TLS, to what Express's trust proxy setting takes: loopback, a hop count such as 1, or the proxy's addresses. |
NODE_ENV |
Set it to production outside a local run. |
PORT |
The port to listen on; 8080 by default. |
Requirements: Node.js 22.12 or later.
@udibo/oauth2 ships a development identity provider, configured here by
idp.json: the synthetic users from seed.js, under the same
ids, this app's client, two machine clients, and step 1's three clients with
their redirect URIs. Its state lives in memory, and it is for development and
CI only.
npm ci
cp .env.example .env
# Replace the SESSION_SECRET placeholder in .env with a fresh random value before npm start.
npx udibo-oauth2 idp dev --config idp.json # in one terminal: http://127.0.0.1:9000
npm start # in another: http://127.0.0.1:8080Open http://127.0.0.1:8080/home and sign in as alice / alice-password.
Use 127.0.0.1 rather than localhost: the issuer and the registered
redirect URI name 127.0.0.1, and the session cookie belongs to the host you
open.
A machine client gets a token for this API from the provider:
curl -u example-machine:example-machine-secret \
-d grant_type=client_credentials \
http://127.0.0.1:9000/tokenThen call GET http://127.0.0.1:8080/protected with
Authorization: Bearer <access_token>. A token from other-api-machine,
which the provider issues for another audience, is refused with 401.
Step 1's clients, example-client, other-client and public-client, used
the app as their authorization server. At step 2 the app has no authorization
endpoints, so each of them moves to the provider:
- Endpoints. The client reads them from the provider's discovery
document,
<issuer>/.well-known/openid-configuration, instead of the app's/.well-known/oauth-authorization-server, which is gone. The local provider's are/authorize,/token,/revokeand/introspect. - Registration. Each client is registered at the provider with the
redirect URIs it had.
idp.jsondoes this for the local provider, under the same ids and secrets, so you can try a client unchanged apart from its endpoints. On a Udibo tenant, register each client again. Give each client its new ID. Provision a new secret only for a confidential client. The public client uses its new ID and PKCE. - The request. Unchanged from step 1: PKCE (S256) and
stateon every authorization request, and the scope it asked for before. The provider's tokens for these clients are JWTs for this API's audience, so/protectedaccepts them. - Consent.
idp.jsonsets"consent": "auto", so the local provider grants a step-1 client what it asks for once the user signs in, with no approval page; step 1 showed one. On a Udibo tenant, the application's Type decides: a third-party application gets the consent screen, a first-party one does not unless it sendsprompt=consent(When people see the consent screen). Register step 1's clients as third-party unless you build them yourself. - The switch. Step 1 kept every token in memory, so stopping it ends
every code and token, as any restart of step 1 does. Clients switch their
endpoints and credentials when step 1 stops, and users sign in again at the
provider. Their
isscheck now expects the provider's issuer.
Until step 3, your existing users have no account at a Udibo tenant. Move a live app only once step 3 has imported them.
Register the app in your tenant's dashboard as described in Connect your first application:
- Create a confidential application with the authorization code
grant, and register its callback URL exactly, for example
https://app.example.com/callback. Register a post-logout redirect URI too if you setAUTH_POST_LOGOUT_REDIRECT_URI. - Choose JWT access tokens, with your API's origin as the audience,
for example
https://app.example.com. - Allow the
openidandprofilescopes. - Put the tenant's issuer, the client id and secret, the callback URL and the audience in the app's environment. Nothing else changes.
Use separate registrations for development and production. Each environment keeps its client secret in its own secret store.
POST /logout ends the app's session. When the provider advertises an
end_session_endpoint, the app then sends the browser there with an
id_token_hint, so the provider's session ends too. The local identity
provider does not advertise one
(udibo/oauth2#177), so after
signing out there, the next sign-in completes without asking for the password
again. Sign-out takes a POST: a link or an image on another page cannot sign
a user out, and the SameSite=Lax session cookie is not sent with a
cross-site POST.
/protected verifies tokens locally, so it does not see a revocation at the
provider: a revoked access token keeps working until it expires. Keep access
tokens short-lived.
The app keeps sessions in memory with
memorystore, which drops each
session once its lifetime has passed and checks for expired ones every minute.
A session that only waits for a sign-in to finish lives ten minutes, as long
as a pending sign-in may. A signed-in session lives SESSION_TTL_SECONDS from
sign-in.
The session cookie is HttpOnly and SameSite=Lax, and Secure whenever
AUTH_REDIRECT_URI is an https URL. Behind a proxy that terminates TLS, the
app sees plain HTTP unless TRUST_PROXY lets it read the proxy's
X-Forwarded-Proto; without it, express-session will not send a Secure
cookie, and sign-in cannot finish.
CORS, open to any origin on every route through step 1, now covers only
/protected and /public. They read no cookie, and the pages that do send no
CORS headers.
An unexpected error gets a 500 with a fixed message, and the details go to
the log. Set NODE_ENV=production as well, as Express recommends for any
production deployment.
The behaviour tests now sign in through the provider, filling in its sign-in
page over HTTP as a browser would. Without AUTH_ISSUER set, they start the
local provider from idp.json on a free port, with five-second access tokens,
and stop it when they finish.
The step-1 behaviours that still belong to the app keep their tests:
| Test | At step 2 | Why |
|---|---|---|
| Serves the public resource to anyone | Unchanged. | |
| Serves the protected resource for the user's access token, naming the user | The token is the provider's JWT, from a user's sign-in, and accessedBy is its subject. |
The provider issues the tokens. |
| Refuses the protected resource without a token, or with an unknown one | Unchanged, with WWW-Authenticate: Bearer. An ID token is refused too. |
|
| Refuses a refresh token used as an access token | The refresh token is the provider's, issued to a step-1 client registered there. | The provider issues the tokens. |
| Allows any origin to call the API from a browser | Now /protected and /public only; a page answers no CORS headers. |
The app now has pages that read a session cookie. |
| Expires access tokens | Waits out the provider's access-token lifetime; skipped against a provider whose tokens live longer than a minute. | The provider sets the lifetime. |
| Starts a new session when a user signs in | The new session starts at the callback, and the session that started the sign-in is no longer honoured. | The provider signs users in. |
| Refuses a wrong password | At the provider's sign-in page, which then sends no code to the app. | Same. |
| Redirects to the client with a code, its state and the issuer | The app now checks them: a callback whose iss names another issuer is refused, and the genuine one still completes. |
RFC 9207 is now the app's check to make. |
The tests of the authorization page, the authorization and token endpoints,
PKCE, refresh rotation, revocation, introspection and the metadata document
are gone. Those endpoints are the provider's now, and the app has none of
them. One test checks that a step-1 client, registered at the local provider
with its old redirect URI, signs a user in there and calls /protected with
the token it gets.
New at step 2:
- A callback is accepted only from the browser that started the sign-in. One
carrying another browser's code and
stateis refused, and the code stays unspent, so an attacker cannot sign a victim in to the attacker's account. - A callback with an unknown
state, anerroror no code is refused, without a session. /protectedrefuses a token the provider issued for another audience.- Sign-out ends the session and follows the provider's end-session endpoint
when there is one; a
GETdoes not sign out. - The return path is checked twice, each check with its own test: when
/loginrecords it, and again when the callback follows it. - Sessions of sign-ins started and never finished are dropped once their
lifetime passes, the session cookie is
Securewhen the app is served overhttps, and the app refuses to start withoutSESSION_SECRET. - An unexpected error is answered with a fixed message, and so is a userinfo endpoint that does not answer within five seconds. A userinfo answer without a subject ends the sign-in without a session.
- A browser keeps its last ten pending sign-ins; the callback of an older one
is refused. A callback carrying an
erroris never redeemed, even beside a code, and itsstatecannot be used again.
npm audit reports no advisories at step 2 (checked 2026-11-06).
- Sessions live in the app's memory. They expire and are dropped, but a
restart signs everyone out, and instances do not share them: use a shared
session store before running more than one instance. Every anonymous visit
to
/loginholds a session for up to ten minutes, so put a rate limit in front of/loginon a public deployment. seed.jsstill holds step 1's users with plain-text passwords, until step 3 imports them./protectedchecks no scope, as in every step before.
Step 3 adds a command that exports the source users as bcrypt import records. The customer and Udibo coordinate the hosted import. Register each destination client separately. The app continues to use the issuer configured at step 2.
Everything step 1 knew about users came from seed.js: its store was in
memory and loaded the seed at start. So seed.js is the users table here,
with every password in plain text, and the step-1 server's memory holds a
copy while it runs. If your step-1 server loaded its users from somewhere
else, export from there; --from below takes any module that exports
{ users: [{ username, password }] }.
The order matters, and each part below follows it:
- Export the users to a file.
- Import the file into your Udibo tenant.
- Verify that imported users sign in.
- Move the clients to their new registrations.
- Retire the step-1 server and
seed.jsonce nothing signs users in from them.
-
Usernames must be unique. Nothing in step 1 enforces it. Udibo usernames are unique per tenant, so the import cannot bring in two users with the same username. The import also trims leading and trailing spaces, so
aliceandalicecollide too. If you leave one in, the import keeps the first record with that username and skips the rest as duplicates. -
Usernames must be ones a user can sign in with. Step 1's users have no email addresses, so each user signs in at Udibo with their username alone. The import refuses a record whose username holds an
@, looks like a phone number (seven or more digits, with nothing but+, spaces,-,.and brackets around them), or is longer than 50 characters. Udibo's sign-in page would read such a username as an email address or a phone number, or could not hold it. Give those users a new username first.Use this preflight to find common problems in the local seed. Check for existing destination usernames separately using the import report.
node -e ' const { users } = require("./seed"); const seen = new Map(); for (const { username } of users) { const key = typeof username === "string" ? username.trim() : ""; const digits = key.replace(/[^0-9]/g, "").length; if (!key || key.includes("@") || key.length > 50 || (/^\+?[0-9\s().-]+$/.test(key) && digits >= 7)) console.log("review:", username); if (seen.has(key)) console.log("duplicate:", username); seen.set(key, true); }'
-
Freeze account changes from export through cutover, or agree how to reconcile them with the operator. A later import can add new accounts. It skips an existing username, so re-exporting a changed password will not update that account.
npm run export:users -- /secure/path/users.ndjsonThe command reads seed.js (or the module --from=<path> names) and writes
one NDJSON record per user, and
prints only a count:
{"username":"alice","legacyCredential":"$2b$12$…"}| Field | What it holds |
|---|---|
username |
The user's username, unchanged. The user signs in with it at Udibo. |
legacyCredential |
A bcrypt hash of the user's password, made by the export. |
Step 1 holds passwords in plain text, so the export hashes each one with
bcrypt (bcryptjs, which is pure
JavaScript and needs no build step). The cost is 12 by default, the highest
Udibo's import accepts; --cost=10 or --cost=11 takes less. In our runs,
cost 12 took about 0.3 seconds per user and cost 10 about 0.1 seconds, so for
many users, expect the export to take a while at the default. bcrypt reads only the first
72 bytes of a password; a longer password still verifies, on those 72 bytes.
The export says how many passwords that applies to, without naming them.
The export omits the source user ID. Keep a separate source-ID mapping and reconcile each import outcome. Verify the destination subject before transferring app data. A matching username alone cannot establish that an existing destination account belongs to the same person.
The file holds no password, but it holds a hash of every one, and anyone with the file can try guesses against those hashes offline; weak passwords fall first. The export:
- writes the records to
<file>.partial, created with mode0600and readable by its owner only, and moves it to<file>only once every user is written; - refuses a path that already exists, rather than overwriting it or taking
on its permissions, and refuses an existing
<file>.partial, or a link there, too. If<file>appears while the export runs, it is left as it was and the export fails; - never writes the records to the terminal, and removes the partial file if
the export fails or is interrupted with Ctrl-C (
SIGINT),SIGTERM, orSIGHUP(the terminal closing). ASIGKILL, or the machine stopping, can still leave<file>.partialbehind: delete it before you run the export again.
Write it outside the repository and anything that syncs or backs up
automatically, and send it only through the channel Udibo gives you for the
import, not by email or chat. Once the import is verified, delete the file and
every copy made on the way. The repository's .gitignore ignores *.ndjson
and *.ndjson.partial, in case one is written inside it.
Today, Udibo runs the import for you: you send the file, Udibo imports it
into your tenant and returns the import report: the number of users
imported, the number skipped because their username was already taken, and
each record it refused, with the reason. Each imported user keeps their
legacyCredential until their first sign-in.
Importing the same file again imports no one: every user is skipped as a duplicate, and a user who has already signed in keeps their upgraded password.
For a newly imported username with a supported bcrypt hash, verify the following at the destination. The manual rehearsal below records the outcome for the seeded accounts.
- They sign in at your tenant's sign-in page with the same username and password they used before. The page asks for an email or username; they enter their username. There is no password-reset email and no new password to choose.
- That first sign-in checks the password against the imported bcrypt hash, then upgrades the stored credential to Udibo's own password hashing. From then on, the imported hash is no longer used.
- Step 1's users have no email addresses, so the import carries none. A user who forgets their password has nowhere to receive a reset until an email address is added to their account. The sign-in page still offers "Forgot password?" and a sign-in code by email; neither can reach a user without an email address.
- Reconcile the number of input records with the imported, skipped and refused counts. Review each skip or refusal and verify the destination account before assigning any existing app data.
- Imported users sign in with their existing passwords. Try it with a synthetic user in a test tenant before your production tenant.
Then delete the file.
On 2026-11-06 we ran the import tool directly on a local Udibo development server. The run below records what happened to two synthetic users. Hosted hand-off and first sign-in after a hosted import need a separate rehearsal.
- Versions: the app used
@udibo/oauth20.46.0 and Node.js 26.12.1. - Tenant: a new tenant with this app registered as a confidential
Development application with the authorization code grant, JWT access
tokens for the audience
http://127.0.0.1:8080and the callbackhttp://127.0.0.1:8080/callback, plus the two machine clients the behaviour tests use. - Export:
npm run export:userswrote the two seed users,aliceandbob, at bcrypt cost 12, to a file with mode0600. - Import:
Imported 2 (0 identity link(s)), skipped 0 duplicate(s), 0 error(s).Both users held their bcrypt hash and no Udibo password. - Sign-in:
alicesigned in through this app's/loginat the tenant's sign-in page withalice-password, with no reset and no other prompt./homeshowed "Signed in as alice", and/protectedaccepted an access token issued for this app's audience, naming her new id. After that first sign-in her bcrypt hash was gone and a Udibo password hash was stored in its place. Her second sign-in worked, and a wrong password was refused at the sign-in page. - Import again:
Imported 0 (0 identity link(s)), skipped 2 duplicate(s), 0 error(s).alicekept her upgraded password. bobsigned in for the first time afterwards, his hash upgraded the same way.- Refused usernames: a separate synthetic file showed records without an
email refused for the usernames
carol@example.test,5555550123,+1 555 555 0123,(555) 555-0123and a 51-character name, and a second record foraliceskipped as a duplicate. - Behaviour tests: the behaviour file alone against this tenant
(
node --env-file=<the tenant's settings> --test test/behavior.test.js): 27 passed, and three were skipped: the two that need a second test user or a step-1 client the tenant does not register, and the access-token expiry test, because the tenant's access tokens live an hour.
Each client needs a new registration. Use the destination’s discovery document for endpoints, configure the new issuer and client ID, and provision a secret only for confidential clients. Keep the public client secretless and use S256 PKCE. See What step 1’s clients see.
- Register each client at Udibo. Give each the grants it uses at step 1, the authorization code grant and refresh tokens, with its redirect URIs registered exactly. Choose JWT access tokens with your API's audience, as in Point it at a Udibo tenant, and third-party unless you build the client yourself.
- Move the clients together when the step-1 server stops. Deploy their new settings at the switch. Users sign in again at Udibo. Stopping the old process invalidates the tokens it stored in memory.
Why together, where the oauth2-server 3.x example moves its clients one at a
time: there, the step-1 server keeps its tokens in PostgreSQL, so an API can
read them beside Udibo's for the transition. Here, step 1 keeps every token
in the memory of its own process, and nothing else can read them:
- No other process can check a step-1 token. A second token reader for the API would need the step-1 server's store, which exists only inside that process. Its introspection endpoint is no substitute: it answers a confidential client only about the client's own tokens, so an API cannot ask about tokens issued to other clients without changing that policy.
- A transition window would mean running both servers side by side: the
step-1 server, deployed as it was at the
step-1-udibo-packagetag, still serving/protectedto the clients that have not moved, and the step-2 app serving the ones that have. Both serve/protected, so they need two origins, and each client calls the one whose server issued its token. That works only if the step-1 server keeps running, signing users in fromseed.jswith their plain-text passwords, for as long as the window lasts. - Nothing outlives the switch anyway. Every code and token step 1 issued ends when it stops, as at any restart, so a client that has not moved by then has its users sign in again either way.
An installed client, such as a mobile or desktop app, has moved only when its users have updated; older copies keep calling the step-1 server, so a side-by-side window lasts until they have. During one:
- The same person has two IDs. Use the verified mapping from the source user ID to the destination
subwhen reading existing app data. - Scopes differ. Step 1 grants
readandwriteand gives a request with no scoperead; Udibo grants the scopes you configure. An API that checks scopes must accept each server's.
Once the import is verified and the last client that signs users in has
moved, stop the step-1 server and delete seed.js from wherever it ran:
- Stopping the server drops the copy of every password it held in memory, and every token it issued.
- Deleting
seed.jsremoves the plain text from that machine's files. This repository keepsseed.jsbecausenpm run export:usersreads it; your deployment has no reason to.
Why this order:
- Not before the import is verified.
seed.jsis the only source of the export. If the import has to be redone, you export again. - Not while the step-1 server signs users in. It loaded every password at start and checks sign-ins against them.
- Then promptly. Every day it stays, it holds every password in plain text.
Plain text can still survive outside it:
- Version control. If
seed.jswas ever committed, every password is in the repository's history and in every clone. Deleting the file does not remove it from history; treat those passwords as known to anyone who can read the repository. Here they are synthetic. - Backups, images and copies of the step-1 deployment taken while
seed.jswas on it. Destroy them as they leave your retention window. - The storage under the deleted file. Deleting it does not wipe the disk blocks under it.
The behaviour tests do not change at step 3: the app's protocol is the same. New at step 3:
- Every seeded user is exported, and each hash verifies against that user's password and not against a different one.
- No plain-text password reaches the file, the terminal or the error output.
- The users of the module
--fromnames are exported instead of the seed's. - The file is created with mode
0600. An existing file, an existing.partialfile or a link there, and a file that appears while the export runs are all left as they were, and an existing file is refused before any user is read. - A failed export, and one interrupted with
SIGINT,SIGTERMorSIGHUP, stops promptly and leaves no file behind; a failure prints no password. - A bcrypt cost outside 10 to 12 is refused, and the count of passwords longer than 72 bytes is printed without the passwords.
- The export needs an output path, and writes nothing to stdout without one.
npm audit reports no advisories at step 3 (checked 2026-11-06). Step 2's
caveats about in-memory sessions and /protected checking no scope still
apply. seed.js still holds the synthetic users' plain-text passwords, for
the export; a deployment deletes its copy as above.
Step 3 carries every password across as a bcrypt hash, and for this app that
is the better path: no network call at sign-in, and nothing to keep running.
Step 4 shows the other path, for a previous system whose hashes Udibo cannot
read, or that exports none. Each user is imported with a remotePassword
that names their step-1 user instead of a hash, and the Udibo tenant registers
a migration source: an HTTPS endpoint this repository runs in front of
step 1's users in seed.js. Such an account is pending: it has no password Udibo can
check by itself. The first time its owner signs in at Udibo, Udibo sends the
password they typed to the endpoint once. When the endpoint confirms it,
Udibo stores the password in its own format and signs the person in, and
that person's later sign-ins never reach the endpoint. The app does not
change.
Udibo's
password migration guide
is the reference for all of it, and its reference endpoint is the core of
password-check.js. Step 4 takes the place of step 3's import: decide before
you import, because a later import skips an account that already exists.
- Udibo sends each pending user's plaintext password to your endpoint,
once for each sign-in attempt that reaches a check. The endpoint must treat
it as a password:
password-check.jsnever logs a request body. seed.jsand the endpoint stay up until the end date you set. The endpoint holds every password in memory while it runs, as the step-1 server did, and retiringseed.jswaits until then (After the end date).- Failed password sign-ins on the Udibo tenant get slower, for every account, while the source is on.
- Pending users share one pause. After five checks in a row that get no usable answer, Udibo sends none for 60 seconds, for every pending user on the tenant, then tries one.
npm run export:users -- --remote-password /secure/path/users.ndjsonEach record names the user by their step-1 id instead of carrying a hash.
--from works as at step 3, and its module's users then need an id; the
command refuses a user without one and writes no file:
{"username":"alice","remotePassword":{"subject":"user-alice","login":"alice"}}| Field | What it holds |
|---|---|
username |
The user's username, as at step 3. |
remotePassword.subject |
The user's id. The endpoint checks the password of the user with this id, and Udibo accepts its answer only for this subject. |
remotePassword.login |
The username again. Udibo sends it with each check as a hint; the endpoint does not use it, since a username can move between users. |
The file holds no password and no hash, but it maps every account to its
step-1 user: keep the step-3 handling (The file is a credential),
which the command applies the same way. --cost does not apply, and the
command refuses it beside --remote-password. Before you export
applies unchanged.
npm run password-check -- [--from=<module>]It reads the users from seed.js, or from the module --from names, once
at start, so it serves the users as they were when it started.
| Environment variable | What it holds |
|---|---|
PASSWORD_MIGRATION_SECRET |
The pmsec_ signing secret Udibo shows once when you connect the source (below). |
PASSWORD_CHECK_TLS_CERT, PASSWORD_CHECK_TLS_KEY |
PEM files for HTTPS. Without them it serves plain HTTP, for a proxy in front of it that terminates TLS. |
PASSWORD_CHECK_HOST, PASSWORD_CHECK_PORT |
Where it listens: 127.0.0.1 and 3001 by default. |
It answers POST /password-check and nothing else:
- It verifies Udibo's signature first, and answers
401without reading the password when the signature, the timestamp (more than five minutes from its clock) or the request id does not hold. A request signed with the old and the new secret while a rotation overlaps is accepted. - It answers the test call with the request's id.
- It answers
no_matchto a check that names no subject. Udibo sends those only when the tenant also checks people it did not import (the guide's Check people you didn't import), which needs an endpoint that can create a profile. Leave that off with this endpoint: every such sign-in is refused. - It checks the user whose
idissubject, comparing the password in constant time, and answersmatchwith that subject, orno_match. An unknown subject isno_match. - It limits failures per subject: after 10 failed checks in 15 minutes it
answers
no_matchfor that subject, even for the right password, until the 15 minutes pass. Only failures for a subject that names a user count, so the counts stay as few as your users. At Udibo's default lockout of 10 attempts, the checks Udibo sends stay within it; the limit is for someone who obtained the signing secret and sends requests straight to the endpoint. It counts in the process's memory, so with more than one instance behind a load balancer each counts on its own.
Udibo calls the endpoint over HTTPS at a public address, and refuses an answer with a compressed body: turn off gzip and Brotli for this route at any proxy in front of it, and keep request bodies out of the proxy's logs.
In the Udibo tenant's dashboard, open Sign-in → Migration, which needs the Manage password migration permission (the Owner access level holds it by default):
- Check against your own endpoint. Enter the endpoint's URL, such as
https://legacy.example.com/password-check. - Pick the end date, at most a year away. Checks stop at 00:00 UTC on that day.
- Leave "Start checking passwords now" off and connect, confirming with your own Udibo password or an authenticator code.
- Save the signing secret the page shows once, as
PASSWORD_MIGRATION_SECRET, and start the endpoint. - Send a test call under Test call. It carries no password; a
401(shown as "a status other than 200") means the endpoint holds the wrong secret or its clock is off. - Turn it on under Status, confirming again.
Udibo sends checks only while the tenant's Security → Attack protection → Mode is Enforce, the default.
Udibo runs the import on a hosted tenant: you send the file and ask
(Udibo runs the import for you).
A wrong subject looks like a wrong password every time, and a mapping
cannot be corrected after the import, so send a file with one test user's
line first:
(umask 077 && grep -F '"username":"alice"' /secure/path/users.ndjson > /secure/path/users-test.ndjson)Sign in to the app as that user with their step-1 password. The tenant's
audit log records
auth.password.upgraded with verifierId remote:endpoint when it works.
When it is refused although the password is right, the latest
auth.sign_in.failed event's reason says why: migration_unavailable
when the endpoint was reached and gave no usable answer, wrong_password
when it answered no_match, not_checked when Udibo paused checks, and
no_password when the source is off, past its end date, or protection is
not on Enforce. Then send the full file; it skips the test user.
Status on the Migration page then shows Pending users and Migrated users.
- The same sign-in page as at step 2, with their username and step-1 password. The first sign-in waits for the endpoint's answer, which Udibo gives up on after 2 seconds; later ones do not involve it.
- Every refusal is the normal sign-in error: a wrong password, the endpoint down, the source off. The person cannot tell them apart.
- Step 1's users have no email addresses, so a pending user cannot use "Forgot password?" or an emailed code, as at step 3. An administrator adds an address or sets a temporary password from the user's page.
Udibo sends no more checks, whatever the switch says. A user who never signed in is left with no password at Udibo, and an administrator sets one for them, since the import carried no email. Tell them before the date.
Then delete the source under Danger zone, stop the endpoint, and delete
seed.js as Retire the local passwords
describes. Until then it holds every password in plain text, as at step 3,
so set an end date no later than you need.
- The endpoint and the export:
npm testcovers the signature, timestamp and id checks, the test call,matchandno_match, a subject sent with another user's login and password, the failure limit, and theremotePasswordrecords, with nothing logged. It needs no database or network service. - Against Udibo: on 2026-12-02 we ran it against a local Udibo built
from the udibo/udibo commit
bb080b0, with Node.js 26.14.0. A migration source pointed atnpm run password-check, served over HTTPS with a test certificate, through Udibo's own outbound client and signer. The import ofnpm run export:users -- --remote-passwordreported 2 imported, 0 skipped, 0 errors, and both users were pending.alicesigning in withbob-passwordwas refused and stayed pending;alicewithalice-passwordsigned in, and the audit log recordedauth.password.upgradedwithverifierIdremote:endpoint. Her pending state was replaced by a Udibo password hash, and with the endpoint stopped she signed in again. - Not run here: a hosted tenant, the dashboard's forms, and the import Udibo runs for you. The live-tenant workflow signs in as a user created in Udibo, so it never reaches a check.
npm testThe behaviour tests (node:test, test/) start the app on a port the system
picks. Without AUTH_ISSUER set, they also start the local identity provider
from idp.json on a free port and stop it when they finish, so they need no
database or network service.
The export tests (test/export-users.test.js) run the step-3 export against
seed.js and synthetic users in a temporary directory.
The password-check tests (test/password-check.test.js) serve step 4's
endpoint on a free loopback port and sign each request the way Udibo does.
With AUTH_ISSUER set, npm test runs against that provider instead. Use a
tenant that holds synthetic users only. It needs:
- the app's registration, as in
Point it at a Udibo tenant, with one
difference: it is a Development application, whose callback URL is an
httploopback URL, such ashttp://127.0.0.1:8080/callback. A Production application accepts onlyhttpscallbacks for a web app. The tests serve the app over plain HTTP on127.0.0.1, and the app marks its session cookieSecurewhenever the callback ishttps, so with anhttpscallback no session survives and the sign-in tests fail. The tests never follow the callback URL themselves, so it only has to be registered; nothing needs to listen there. - a machine client with the client-credentials grant and JWT access tokens for the app's audience;
- a second machine client whose JWT access tokens are for another audience;
- a synthetic user who signs in with a username and password and has no second factor. With a second factor the provider stops at its second-factor page, and every test that signs in fails there.
| Environment variable | Repository secret for the live-tenant workflow |
|---|---|
AUTH_ISSUER |
UDIBO_ISSUER |
AUTH_CLIENT_ID |
UDIBO_CLIENT_ID |
AUTH_CLIENT_SECRET |
UDIBO_CLIENT_SECRET |
AUTH_REDIRECT_URI |
UDIBO_REDIRECT_URI |
AUTH_AUDIENCE |
UDIBO_AUDIENCE |
TEST_USERNAME |
UDIBO_TEST_USERNAME |
TEST_PASSWORD |
UDIBO_TEST_PASSWORD |
TEST_MACHINE_CLIENT_ID |
UDIBO_MACHINE_CLIENT_ID |
TEST_MACHINE_CLIENT_SECRET |
UDIBO_MACHINE_CLIENT_SECRET |
TEST_OTHER_AUDIENCE_CLIENT_ID |
UDIBO_OTHER_AUDIENCE_CLIENT_ID |
TEST_OTHER_AUDIENCE_CLIENT_SECRET |
UDIBO_OTHER_AUDIENCE_CLIENT_SECRET |
The tests that need a second user or a step-1 client skip there, and so does the expiry test when the tenant's access tokens live longer than a minute. The live-tenant workflow runs on demand and every Monday. Until every secret above is set, it reports which are missing and passes without running the tests.
| Step | Node.js | Recorded step run |
|---|---|---|
step-0-upstream |
22 and 24 (CI), 26 (local) | 2026-11-05 |
step-1-udibo-package |
22 and 24 (CI), 26 (local) | 2026-11-05 |
step-2-udibo-idp |
22 and 24 (CI), 26 (local), against the local identity provider | 2026-11-06 |
step-3-user-import |
22 and 24 (CI), 26 (local), against the local identity provider; 26 against a local Udibo development server | 2026-11-06 |
step-4-password-migration |
22 and 24 (CI), 26 (local); 26 against a local Udibo development server | 2026-12-02 |
Main CI at e0c72e2 exported both users from the in-memory example’s seed on Node 22 and 24. The November 30 hosted-tenant run exercised the configured development tenant (43 passed, 3 skipped). The November 6 import and password upgrade above were verified by hand on a local development server.
The README of upstream's authorization-code directory, as published, with
headings demoted to fit this page. It describes the provider and the client
application together, and its .env values are upstream's; this repository
uses the seed above instead.
Caution
Do not use this example in production 1:1. It is meant for educational purposes and needs to be adapted to your specific use case. It is a minimal example that does not include all necessary security measures.
The authorization code workflow is described in RFC 6749, section 4.1:
+----------+
| Resource |
| Owner |
| |
+----------+
^
|
(B)
+----|-----+ Client Identifier +---------------+
| -+----(A)-- & Redirection URI ---->| |
| User- | | Authorization |
| Agent -+----(B)-- User authenticates --->| Server |
| | | |
| -+----(C)-- Authorization Code ---<| |
+-|----|---+ +---------------+
| | ^ v
(A) (C) | |
| | | |
^ v | |
+---------+ | |
| |>---(D)-- Authorization Code ---------' |
| Client | & Redirection URI |
| | |
| |<---(E)----- Access Token -------------------'
+---------+ (w/ Optional Refresh Token)
- @node-oauth/express-oauth-server (uses @node-oauth/oauth2-server)
- express
- body-parser
- cors
- express
- ejs
- Install dependencies in both provider and client directories:
cd provider && npm install
cd ../client && npm install- Create a
.envfile in the authorization-code/provider directory:
CLIENT_ID=testclient
CLIENT_SECRET=testsecret
REDIRECT_URI=http://localhost:3000/callback
USER_ID=user1
OAUTH_USERNAME=demo
OAUTH_PASSWORD=demo
- Create a
.envfile in the authorization-code/client directory:
AUTH_SERVER=http://localhost:8080
CLIENT_ID=testclient
CLIENT_SECRET=testsecret
REDIRECT_URI=http://localhost:3000/callback
- Start the provider (authorization server + resource server):
cd provider && npm start- Start the client application:
cd client && npm start- Visit http://localhost:3000 to start the authorization code flow.
This example demonstrates a clear separation between the OAuth2 provider (authorization server + resource server) and the client application. Unlike other examples that might combine both roles in a single application, this example shows:
- Provider (port 8080): Acts as both authorization server and resource server
- Client (port 3000): A separate web application that consumes OAuth2 services
This separation makes it easier to understand what the @node-oauth/oauth2-server library supports and what it doesn't.
- User visits the client application at http://localhost:3000
- User clicks "Login" to start the authorization flow
- User is redirected to the provider's authorization page
- User enters credentials and grants authorization
- User is redirected back to the client with an authorization code
- Client exchanges the code for an access token
- Client can now access protected resources using the access token