How to use the openid-client.TokenSet function in openid-client

To help you get started, we’ve selected a few openid-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github auth0 / express-openid-connect / lib / context.js View on Github external
makeTokenSet(tokenSet) {
    return new TokenSet(tokenSet);
  }
github magma / magma / nms / app / fbcnms-packages / fbcnms-auth / oidc / middleware.js View on Github external
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('/');
        }