Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Unable to end session for auth provider SSO (Node JS)

I have no idea how to end the session so when a user makes a request to my /logout endpoint, the session is cleared and they are required to log on using SSO again.

Here is my code... so far once i log in initially, no matter what i do, i stay logged in and do not have to enter credentials via my auth provider.

let OpenIDConnectStrategy = require('passport-ci-oidc').IDaaSOIDCStrategy
const passport = require("passport")

app.use(session({ resave: 'false', saveUninitialized: 'false', secret: 'keyboard cat', cookie: false }));
app.use(passport.initialize());
app.use(passport.session());

passport.serializeUser(function (user, done) {
  done(null, user);
});

passport.deserializeUser(function (obj, done) {
  done(null, obj);
});

var Strategy = new OpenIDConnectStrategy({
  discoveryURL: discovery_url,
  clientID: client_id,
  scope: 'openid',
  response_type: 'code',
  clientSecret: client_secret,
  callbackURL: callback_url,
  skipUserProfile: true,
  addCACert: true,
  CACertPathList: [
    '/src/server/DigiCertGlobalRootCA.crt',
    '/src/server/DigiCertSHA2SecureServerCA.crt'
  ]
},
  function (iss, sub, profile, accessToken, refreshToken, params, done) {
    process.nextTick(function () {
      profile.accessToken = accessToken;
      profile.refreshToken = refreshToken;
      done(null, profile);
    })
  });

passport.use(Strategy);

app.get('/login', passport.authenticate('openidconnect', {}));

function ensureAuthenticated(req, res, next) {
  if (!req.isAuthenticated()) {
    req.session.originalUrl = req.originalUrl;
    res.redirect('/login');
  } else {
    return next();
  }
}

app.get('/auth/sso/redirect', function (req, res, next) {
  var redirect_url = req.session.originalUrl;
  passport.authenticate('openidconnect', {
    successRedirect: redirect_url,
    failureRedirect: '/failure'
  })(req, res, next);
});

app.get('/failure', function (req, res) {
  res.redirect('/login')
});

app.get('/logout', ((req, res) => {
  req.logout()
  req.session.destroy((err) => {
    res.clearCookie('connect.sid')
    res.send('logged out')
  })
}))

app.get('/', ensureAuthenticated, function (req, res, next) {
  next()
});

// serve React application 
app.use(express.static(path.join(__dirname, '../../build')))
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!