如何实现/破解GitHub OAuth的两个回调url



我希望能够authenticate(用于与GitHub注册)和authorize(用于链接GitHub帐户到现有帐户)在GitHub OAuth的单独路由中。我用领英OAuth用两个不同的路由处理这个问题,一个调用passport.authenticate(),一个调用passport.authorize()。GitHub只允许你有一个回调URL。

我发现这篇文章解释了一个解决方案,但不知道如何实现答案。

下面是我使用Linkedin OAuth的设置,它工作得很好。

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'
  })
);

如果两个URL在相同的域、端口和协议上,您可以指定一个在您想要使用的URL之上的URL,例如:

,如果您的页面打开https://example.com/oauth/authorizehttps://example.com/oauth/authenticate

你可以将https://example.com/oauth设置为github中的回调URL,并在请求github时抛出redirect_uri参数。

更多:https://developer.github.com/v3/oauth/redirect-urls

最新更新