Reference

Options, failure codes, the errors you'll see while wiring it up, and cookies behind a proxy.

Options

OptionDefault
verify—Required. ( identity, tokens, req ) => user struct or null
loadUsernone( id ) => user struct or null
successRedirect"/"
failureRedirect"/login"?error= (or &error=) is appended
loginPath"/login"
sessionKey"auth"Key under req.session this module owns
stateTtlSeconds600
linknone( identity, user, tokens, req ) => true/false. Turns on POST /auth/:provider/link
linkRedirectsuccessRedirectAfter a link (unless returnTo)
linkFailureRedirectfailureRedirectAfter a failed link, with ?error=

Every provider takes clientId, clientSecret, callbackUrl (all required), scopes, authorizeParams (extra authorize-URL parameters such as { prompt: "select_account" }; the flow's own — state, nonce, scope, redirect_uri, PKCE — can't be overridden), userAgent (default boxlang-express-auth) and httpClient. The OIDC providers (generic, Google, Microsoft, GitLab) add the options on their own pages.

Failure codes

failureRedirect gets ?error= with one of these, and nothing else — a provider's own error text is never echoed:

CodeMeaning
access_deniedThe user declined on the provider's consent screen.
provider_errorThe provider sent back any other error or no code — or, on GET /auth/:provider, an OIDC issuer's discovery document couldn't be read.
invalid_stateState missing, wrong, already used, or no login was pending in this session.
expired_stateTook longer than 10 minutes.
token_exchange_failedThe provider refused the code (GitHub: HTTP 200 with an error body).
profile_failedThe profile couldn't be read, or an OIDC ID token failed validation (the log says which check).
login_deniedverify() returned null.
link_deniedA link was refused: link() returned false or null, or the user who started it is no longer the one signed in. Sent to linkFailureRedirect.

The reason is logged server-side ([BoxExpressAuth] github login failed: …), never with codes, tokens or the client secret.

Errors you'll see while wiring it up

TypeWhen
BoxExpressAuth.SessionRequiredA request reached the auth routes or a guard without boxExpressSession() in front.
BoxExpressAuth.InvalidConfigNo verify function, or loadUser or link isn't one.
BoxExpressAuth.InvalidProviderMissing clientId/clientSecret/callbackUrl, a relative callbackUrl, a bad provider name, an authorizeParams key the flow owns, or (OIDC) a missing or plain-http issuer or no openid scope.
BoxExpressAuth.DuplicateProviderTwo providers registered under one name.

Behind a proxy, and cookies

The callback is a top-level GET from github.com back to your site, so the session cookie must be sent on a cross-site navigation: the default sameSite: "Lax" works; sameSite: "Strict" makes every login fail with invalid_state. Set secure: true on the session cookie once TLS is in front, and app.set( "trust proxy", … ) as BoxExpress's docs describe.

With a database-backed session store, keep boxExpressSession()'s resave: false, saveUninitialized: false.

Consider rate-limiting the auth routes: app.use( "/auth", boxExpressRateLimit( { max: 30, windowMs: 60000 } ) ) before mounting them.