|
|
|
|
@ -11,6 +11,14 @@ import { jwtVerify, createRemoteJWKSet, SignJWT } from 'jose';
|
|
|
|
|
* Using stateless signed state to avoid third-party cookie issues
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export interface OnUserAuthenticatedEvent {
|
|
|
|
|
claims: Record<string, any>;
|
|
|
|
|
tokenResponse: Record<string, any>;
|
|
|
|
|
request: Request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OnUserAuthenticatedHandler = (event: OnUserAuthenticatedEvent) => Promise<void>;
|
|
|
|
|
|
|
|
|
|
interface OidcStandardConfig {
|
|
|
|
|
logger: any;
|
|
|
|
|
sessionService: any;
|
|
|
|
|
@ -35,6 +43,9 @@ interface OidcStandardConfig {
|
|
|
|
|
|
|
|
|
|
// State signing secret (should be different from session secret)
|
|
|
|
|
stateSigningSecret: string;
|
|
|
|
|
|
|
|
|
|
// Optional hook invoked after id_token verification succeeds
|
|
|
|
|
onUserAuthenticated?: OnUserAuthenticatedHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createOidcStandardRoutes(config: OidcStandardConfig): Router {
|
|
|
|
|
@ -299,6 +310,19 @@ export function createOidcStandardRoutes(config: OidcStandardConfig): Router {
|
|
|
|
|
return res.status(401).send('Nonce mismatch');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config.onUserAuthenticated) {
|
|
|
|
|
try {
|
|
|
|
|
await config.onUserAuthenticated({
|
|
|
|
|
claims: payload,
|
|
|
|
|
tokenResponse: tokenData,
|
|
|
|
|
request: req,
|
|
|
|
|
});
|
|
|
|
|
} catch (handlerError) {
|
|
|
|
|
logger.error('onUserAuthenticated handler failed', handlerError);
|
|
|
|
|
return res.status(500).send('Unable to process user registration');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear the optional nonce cookie if it was set
|
|
|
|
|
res.clearCookie('rp_nonce', getCookieOptions());
|
|
|
|
|
|
|
|
|
|
@ -631,4 +655,4 @@ export function createOidcStandardRoutes(config: OidcStandardConfig): Router {
|
|
|
|
|
router.post('/auth/logout', logoutHandler);
|
|
|
|
|
|
|
|
|
|
return router;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|