For OpenID Connect (OIDC) compliance, the server must handle prompt and max_age parameters. Since the library cannot see the session, the /authorize route must manually check session freshness:
prompt=none: The server must not show login or consent forms. If no session exists or approval is missing, redirect to redirect_uri with error=login_required or error=consent_required and the state parameter.max_age: Compare the last login time with the current time. If the session is older than max_age seconds, force the user to re-authenticate and update authRequest.authTime.
const authRequest = await authorizationServer.validateAuthorizationRequest(requestFromExpress(req));
const lastLoginSeconds = req.session.authTime; // set by your login route
const sessionIsStale =
authRequest.maxAge !== undefined &&
(lastLoginSeconds === undefined || lastLoginSeconds + authRequest.maxAge < Math.floor(Date.now() / 1000));
if (!req.user || sessionIsStale) {
if (authRequest.prompt === "none") {
const redirect = new URL(String(authRequest.redirectUri));
redirect.searchParams.set("error", "login_required");
if (authRequest.state) redirect.searchParams.set("state", authRequest.state);
res.redirect(redirect.toString());
return;
}
res.redirect("/login");
return;
}
authRequest.user = req.user;
authRequest.authTime = lastLoginSeconds;