PingFederate - OAuth2.0 - express implementation using passport-ping-oauth2 not working - TypeError: Cannot read properties of undefined Error

44 views Asked by At

Please help, I have been stuck on it for too long and searched everything possible. I have a SPA with reactJS as frontend and Express as backend. My SSO provider is pingFederate and I have used passport-ping-oauth2 for OAuth2.0 implementation.

I have used below code for the implementation in my express :

const clientId = XXXX;
const clientSecret = XXXX;
const authorizationURL = https://example.com/as/authorization.oauth2;
const tokenURL = https://example.com/as/token.oauth2;
const callbackURL = /auth/ping/callback;


passport.use(new OAuth2Strategy({
  clientID: clientId,
  clientSecret: clientSecret,
  callbackURL: '/auth/ping/callback',
  authorizationURL: authorizationURL,
  tokenURL: tokenURL,
}, function (accessToken, refreshToken, profile, done) {
  done(null, profile);
  }
));

passport.serializeUser((user, done) => {
  console.log("Line no 47")
  console.log(user)
  done(null, user);
});

passport.deserializeUser((obj, done) => {
  console.log("Line no 53")
  console.log(obj)
  done(null, obj);
});

router.get("/login/success", (req, res) => {
  console.log("Line no 59")
  if (req.user) {
    res.status(200).json({
      success: true,
      message: "successfull",
      user: req.user,
      //   cookies: req.cookies
    });
  }
});

router.get("/login/token", (req, res) => {
  console.log("Line no 74")
});

router.get("/login/failed", (req, res) => {
  console.log("Line no 71")
  res.status(401).json({
    success: false,
    message: "failure",
  });
});

router.get("/logout", (req, res) => {
  console.log("Line no 79")
  req.logout();
  res.redirect(CLIENT_URL);
});

router.get("/ping", passport.authenticate("oauth2", { scope: ['openid', 'profile', 'email'] }));

router.get(
  "/ping/callback",
  passport.authenticate("oauth2", {
    successRedirect: CLIENT_URL,
    failureRedirect: "/login/failed",
  })
);

Now here is my current flow :

  1. I load the application URL, it goes to SSO login page (correct)
  2. User enters the credentials (correct)
  3. User gets authenticated and gets redirected back to callback URL with a code appended to querystring and then it breaks in strategy.js file of passport library
..node_modules\passport-ping-oauth2\lib\strategy.js:314
  var id_tokenArray = id_token.split(".");
                               ^

TypeError: Cannot read properties of undefined (reading 'split')

Please help. Ideally it should have internally got the access token from code and user profile from it and return it in verify function. But its breaking in the passport library.

0

There are 0 answers