Authentication
Behaviour
Every request passes validateRequestAuth, which calls auth to find the user.[1] A request without a user is anonymous; on a PRIVATE instance it is redirected to the login, ${DIR}${AUTH_PATH}/login (default /api/user/login).
auth takes the first of:[2]
- An
Authorizationheader: email and password checked against the ACL. - A
tokenrequest param, else the cookie named afterTITLE. The JWT is verified withSECRET. Atokenparam with anapiclaim is an API key and is checked against the key stored in the ACL. - With
USER_SESSION, the token's session must match the ACL, so a new login ends earlier sessions. Without it a cookie stays valid until it expires.
For a token or cookie user the roles are expanded: europe.france adds europe, and every such user has *. A user from an Authorization header (HTTP Basic credentials) is returned before this expansion and has only the roles stored in the ACL. Users from a token or API key never have admin rights. /api/user/token issues a token, 8 hours by default; /api/user/key an API key for accounts with the api field set.
Login providers
All providers hand a user to mod/user/redirect.js, which looks the email up in the ACL for its roles, signs the JWT cookie and redirects.[3]
- Built-in:
/api/user/login; see user accounts. - SAML:
apps/samlmounts/saml/login,/saml/acs,/saml/logout,/saml/logout/callbackand/saml/metadata; see the SAML variables in environment. The SAML email must have an ACL record.redirect.jscopiesadminandrolesfrom that record, so a SAML user is an admin when the ACL says so. - Custom:
apps/authis a template provider with/custom/login,/custom/verifyand/custom/logoutroutes;AUTH_PATHpoints the login links and thePRIVATEredirect at it.[4]
Cookies use COOKIE_PROPS, by default Secure; HttpOnly; SameSite=Strict; Path=<DIR or />, and live COOKIE_TTL seconds. A provider setting or revoking a cookie must use the same properties.
Revocation
Cookies, tokens and API keys are signed JWTs. Blocking or unapproving an account stops its logins and cookie renewals, but a cookie or token issued before stays valid until it expires. Keep COOKIE_TTL short. USER_SESSION ends a user's earlier sessions when they log in again. Rotating SECRET or SECRET_KEY invalidates every cookie, token and API key at once; do this when an account must lose access immediately.
Flow
validateRequestAuth → user/auth.js → fromACL.js (header) or jsonwebtoken (token, cookie) → checkParamToken, checkSession. Login: provider → user/redirect.js → Set-Cookie and 302.
Where to change
- Token and session checks:
apps/xyz/mod/user/auth.js. - Cookie signing and claims:
redirect.js,cookie.js,jwtClaims.js. - A new provider: copy
apps/auth, callredirectwith{ email, lookup: true }.
Tests
apps/xyz/tests/mod/user/ covers auth, cookies, tokens, keys and redirects.
Pitfalls
apps/authis a template. Its/custom/verifyroute signs in any ACL account by the posted username, without a password or other credential. Replace the verification before deploying it; never deploy it unchanged (#3166).apps/auth/providerRequestSignature.jsverifies signed provider URLs but is not mounted by the default server; mount it where signed URLs are used.- A deployment over plain HTTP must set
COOKIE_PROPSwithoutSecure.