jaredhanson / passport-github

GitHub authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-github/?utm_source=github&utm_medium=referral&utm_campaign=passport-github&utm_content=about
MIT License
537 stars 290 forks source link

How to use passport-github in a REST API Architecture? #72

Closed rkpattnaik780 closed 5 years ago

rkpattnaik780 commented 5 years ago

I am building a vue.js client which needs to be authenticated through github oauth using an express server. It's easy to do this using server side rendering but implementing it in REST API has been troublesome for me.

I have set the homepage url as "http://localhost:3000" where the server runs and I want the authorization callback url to be "http://localhost:8080" (which hosts the client). I am redirecting to "http://localhost:3000/auth/github/redirect" instead, and in its callback redirecting to "http://localhost:8080". The problem I am facing is that I am unable to send user data to the vuejs client through res.redirect. I am not sure if I am doing it the right way.

router.get("/github", passport.authenticate("github"));

router.get(
  "/github/redirect",
  passport.authenticate("github", { failureRedirect: "/login" }),
  (req, res) => {
    // res.send(req.user);
    res.redirect("http://localhost:8080/"); // req.user should be sent with this
  }
);
zeyadetman commented 4 years ago

Are you still facing this issue? Could you write how you fixed your issue? @rkpattnaik780

rkpattnaik780 commented 4 years ago

Are you still facing this issue? Could you write how you fixed your issue? @rkpattnaik780

Hello @zeyadetman , you can go through this link to know what worked for me. Hope it helps :)