boxlang-express-auth 0.3.0
Released .
- A test provider for apps' own specs (
boxExpressAuthTestProvider(),models/providers/TestProvider.bx).login( app, { identity } )runs the real routes — state, PKCE,verify(), session regeneration — throughapp.inject()and hands back the cookies;denyandfailsimulate a refusal or a broken provider. Its authorize URL is under.invalidand codes only exist once test code callsapprove(), so registering it by mistake doesn't open a login. - Logout at the issuer for OIDC providers (RP-initiated logout). With
postLogoutRedirectUrl,POST /auth/logoutdestroys the session and then sends the browser to the discoveredend_session_endpoint(a303, or200 { logoutUrl }for afetch()). The ID token is kept forid_token_hintonly withlogoutIdTokenHint: true, so by default the session still holds no provider token at all.req.session.auth.providernow records which provider a login came through. - Microsoft (Entra ID) preset (
boxExpressAuthMicrosoft()), withtenant(common,organizations,consumers, a tenant id or domain) andallowedTenants. The multi-tenant endpoints' templated issuer is handled by checking each token'sissagainst its owntid. The email is never reported as verified: Microsoft doesn't verify it. - GitLab preset (
boxExpressAuthGitLab()), for gitlab.com or a self-managedbaseUrl. - Account linking: with a
link( identity, user, tokens, req )option,POST /auth/:provider/linklets a signed-in user attach another provider account. POST only (so it sits behind CSRF protection), same callback and checks as a login, refused withlink_deniedif the signed-in user changed in between.linkRedirectandlinkFailureRedirectoptions. - ES256/ES384/ES512 ID tokens (
models/Jwt.bx), verified against EC JWKs on the curve the algorithm names, for issuers that sign with ECDSA. - Sign in with Apple (
boxExpressAuthApple()). Apple's ID tokens are ordinary RS256; what's different is everything around them:- The client secret is an ES256 JWT signed with the team's
.p8key (teamId,keyId,privateKey), minted fresh with a five-minute lifetime for every code exchange. - Asking for name or email makes Apple return with a cross-site form
POST, which a
SameSite=Laxsession cookie doesn't ride along on. The newPOST /auth/:provider/callbackanswers it with a303to the usual GET callback — a top-level navigation, which does carry the cookie — so every state, PKCE and ID-token check runs unchanged. Onlycode,stateanderrorgo into that URL. - The user's name, which Apple posts once on first authorization and
never in the ID token, is held in memory under a hash of the state
until the GET callback collects it. The posted email and
id_tokenare ignored in favour of the signed token from the token endpoint. auth.formPostRoutes()mounts just that POST route ahead ofboxExpressCsrf(), which would refuse Apple's tokenless POST.
- The client secret is an ES256 JWT signed with the team's
- Providers can now override
clientSecretValue()(what's sent asclient_secret) and receivestateinfetchProfile()'s context. - Guards on WebSocket upgrades:
auth.required()inapp.ws( path, handler, { use: [ sessions, auth.required() ] } )(BoxExpress 0.2.27+) answers an anonymous upgrade with a plain401, never a login redirect, whatever itsAcceptheader says. Covered by a spec against a real listening server. - OIDC subclasses can override
discoveryIssuerMatches()andtokenIssuerAllowed()for issuers whoseissisn't a fixed string.