首页 文章

使用Passport刷新Yahoo OAuth 1.0访问令牌

提问于
浏览
1

我有一个Express应用程序,我试图刷新Yahoo OAuth 1.0访问令牌在一小时后到期,这样用户就不必重新登录了 . 我正在使用https-passport-yahoo-oauth Passport策略,该策略适用于最初的OAuth .

这里有一个用于刷新OAuth 2.0令牌的策略(passport-oauth2-refresh),这是我无法开始工作的(我认为原因很明显) .

雅虎文档在这里刷新访问令牌=> https://developer.yahoo.com/oauth/guide/oauth-refreshaccesstoken.html

这是我的初始OAuth代码如下 . 然后,我如何根据此交换过期或到期令牌?

passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(obj, done) {
  done(null, obj);
});


 var strategy = new YahooStrategy({
    consumerKey: APP_KEY,
    consumerSecret: APP_SECRET,
    callbackURL: (process.env.APP_URL || require('./conf.js').APP_URL) + 'auth/yahoo/callback'
  },
  function(token, tokenSecret, profile, done) {
    var data = profile._json;

    var userObj = {
      id: profile.id,
      name: data.profile.nickname,
      avatar: data.profile.image.imageUrl,
      dateJoined: new Date().getTime(),
      lastUpdated: new Date().getTime(),
      lastVisit: new Date().getTime(),
      accessToken: token,
      tokenSecret: tokenSecret,
      sessionHandle: profile.oauth_session_handle
    };
    return done(null, userObj);
  }
);

passport.use(strategy);

我在想我可以使用Request,然后滚动我自己的令牌刷新,虽然我有点不确定从哪里开始 . 有帮助吗?真的很感激任何建议 .

1 回答

  • 0

    是的,你可以使用request完全做到这一点:

    request.post('https://api.login.yahoo.com/oauth/v2/get_token', {
      oauth: {
        consumer_key:'...',
        consumer_secret:'...',
        token:'...',
        token_secret:'...',
        session_handle:'...'
      }
    }, function (err, res, body) {})
    

    或者你也可以使用Purest . 请注意,当用户第一次授权您的应用时,您应该存储 session_handle .

相关问题