【问题标题】:How to implement/hack two callback URLs for GitHub OAuth如何为 GitHub OAuth 实现/破解两个回调 URL
【发布时间】:2017-03-02 19:24:12
【问题描述】:

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

我发现这个post 解释了一种解决方法,但不知道具体如何实施。

下面是我使用 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'
  })
);

【问题讨论】:

    标签: node.js express oauth-2.0 github-api linkedin-api


    【解决方案1】:

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

    如果您的网页在 https://example.com/oauth/authorizehttps://example.com/oauth/authenticate

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

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

    【讨论】:

      猜你喜欢
      • 2013-04-24
      • 1970-01-01
      • 1970-01-01
      • 2012-07-14
      • 2014-12-29
      • 1970-01-01
      • 2010-09-25
      • 1970-01-01
      • 2012-09-01
      相关资源
      最近更新 更多