我正在使用这个 npm 包针对 Twitter 对用户进行 OAuth Echo 验证:https://github.com/ciaranj/node-oauth
有没有人有如何使用这个包来验证用户凭据的示例?
据我所知,我正在从 iOS 应用程序正确获取 X-Auth-Service-Provider 和 X-Verify-Credentials-Authorization,但我无法将这些 header 与此包一起使用。
这是 OAuthEcho 构造函数:
var oauthEcho = new OAuthEcho(
"https://twitter.com",
"https://api.twitter.com/1.1/account/verify_credentials.json",
app.config.twitter.consumer_key,
app.config.twitter.consumer_private_key,
"1.0A",
"HMAC-SHA1"
);
非常感谢任何帮助!
谢谢!!
最佳答案
哇,我完全错了。我实际上并不需要 oauth 模块。我需要请求模块对 twitters api 进行简单的 GET 调用。
// Setup the request object for OAuth Echo to twitter
var options = {
url: 'https://api.twitter.com/1.1/account/verify_credentials.json',
headers: {
'Authorization': req.headers['x-verify-credentials-authorization']
}
};
// Make the request
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
// If twitter responds with a 200, the echo call was authorized
// TODO: do stuff
next();
} else {
res.send(401, 'Unauthorized');
next();
}
});
关于node.js - 如何进行 Twitter OAuth Echo 验证调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27467102/