0

I want to be able to authenticate(for signing up with GitHub) and authorize(for linking GitHub account to an existing account) in separate routes for GitHub OAuth. I handle this with LinkedIn OAuth with two different routes, one that calls passport.authenticate() and one that calls passport.authorize(). GitHub only allows you to have one callback URL though.

I've found this post explaining a workaround, but do not know exactly how to implement the answer.

Below is my setup with Linkedin OAuth that works fine.

router.get('/auth/linkedin', passport.authenticate('linkedin'));
router.get('/auth/linkedin/callback', passport.authenticate('linkedin', {
  failureRedirect : '/app/#/login'
}), function(req, res){
    res.redirect('/app/#/profile');
});

router.get('/connect/linkedin',
  passport.authorize('linkedin', {
        failureRedirect: '/app/#/login' })
);
router.get('/connect/linkedin/callback',
  passport.authorize('linkedin', {
      successRedirect : '/app/#/profile',
      failureRedirect : '/app/#/login'
  })
);
Community
  • 1
  • 1
lsimmons
  • 677
  • 1
  • 8
  • 22

1 Answers1

1

if both urls are on the same domain, port and protocol, you can speciy a URL that is above the ones you want to use, for example:

if your pages are on https://example.com/oauth/authorize and https://example.com/oauth/authenticate

you can set https://example.com/oauthas callback URL in github and throw in the redirect_uri parameter in the request to github.

more here: https://developer.github.com/v3/oauth/#redirect-urls

My1
  • 475
  • 5
  • 21