Twitter Oauth Token_secret不会被退回

时间:2016-11-30 00:51:14

标签: javascript node.js twitter twitter-oauth restify

当我尝试从twitter获取访问令牌时。我得到了ouath令牌和oauth验证程序,但token_secret仍未定义,因为它没有作为param添加到我的回调网址中。请帮忙

    var OAuth = require('oauth').OAuth;
    var config = require('../config');

// Create the oauth object for accessing Twitter
var oauth = new OAuth(
    config.request_token_url,
    config.access_token_url,
    config.consumer_key,
    config.consumer_secret,
    config.oauth_version,
    config.oauth_callback,
    config.oauth_signature_method
);

module.exports = {
    redirectToTwitterLoginPage: function(req, res, next) {
        const cookies = req.cookies;
        // Ask Twitter for a request token
        oauth.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret) {
            if (error) {
                console.log(error);
                res.send("Authentication failed!");
            } else {
                // Use the request token to take the client to Twitter's authentication page
                res.setCookie('oauth_token', oauth_token, { httpOnly: true });
                res.setCookie('oauth_token_secret', oauth_token_secret, { httpOnly: true });
                res.redirect(config.authorize_url + '?oauth_token='+oauth_token, next);
            }
        });

    },
    authenticate: function(req, res, callback) {

        // Check if the request token and temporary credential are there

        if (!(req.cookies.oauth_token && req.cookies.oauth_token_secret && req.cookies.oauth_verifier)) {
            return callback("Request does not have all required keys");
        }


        // Clear the request token cookies
        res.clearCookie('oauth_token');
        res.clearCookie('oauth_token_secret');

        // Tell router that authentication was successful
        callback();
    }
};

0 个答案:

没有答案