Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
makeTokenSet(tokenSet) {
return new TokenSet(tokenSet);
}
return async function access(
req: FBCNMSRequest,
res: ExpressResponse,
next: NextFunction,
) {
try {
const passportTokenSet = req.session?.oidc?.tokenSet;
if (!passportTokenSet) {
next();
return;
}
const tokenSet = new TokenSet(passportTokenSet);
if (!tokenSet.expired()) {
next();
return;
}
const client = await clientFromRequest(req);
const newToken = await client.refresh(tokenSet.refresh_token);
req.session.oidc = {tokenSet: newToken};
next();
} catch (error) {
if (error.name === 'OpenIdConnectError') {
if (error.error === 'invalid_grant') {
req.logout();
delete req.session.oidc;
res.redirect('/');
}