nodejs中的dropbox api用法“oauth_signature_method的Bad oauth_signature”

时间:2011-12-23 12:56:07

标签: node.js dropbox-api

我一直在尝试连接到Dropbox服务器并使用api,但我在第一步就失败了。当我请求请求令牌时,我在nodejs中收到Bad oauth_signature错误。

我用来连接api的代码如下。(我正在使用https://github.com/sintaxi/node-dbox/blob/master/README.md library / sdk for nodejs)

/*
 * dropbox handlers controller.
 */

var dbox = require('dbox')
   ,querystring = require("querystring")

var client = dbox.createClient({
    app_key    : 'my-key',             // required
    app_secret : 'my-secret',           // required
    root       : 'sandbox'            // optional (defaults to sandbox)
  })

exports.index = function(req, res){

  client.request_token(function(status, reply){
    console.log(status)
    console.log(reply)
  // {
  //   oauth_token        : "h89r0sdfdsfwiko",  // required
  //   oauth_token_secret : "8hielfflk7100mv",  // required
  // }
  })

我在控制台中获得的结果如下

c:\ tmp \ dropbox>节点app.js Express服务器在开发模式下侦听端口3000 oauth_consumer_key = [我的钥匙]& oauth_signature = faawn09ehmfe25i%2526& oauth_ti mestamp = 1324643574&安培; oauth_nonce = 132464357437334176&安培; oauth_signature_method = PLAINTE XT&安培; oauth_version = 1.0 403 {'{“error”:“oauth_signature_method \'PLAINTEXT \'的错误oauth_signature \'”}':u ndefined}

非常感谢任何帮助。 提前致谢

3 个答案:

答案 0 :(得分:4)

这是node-dbox的作者。从版本0.2.2开始,此问题已得到解决。

不好意思。

答案 1 :(得分:2)

我采用了passport模块及其配套passport-dropbox模块的方法来处理与Dropbox进行身份验证握手所需的路由。收到Dropbox回调中传递的令牌和令牌密钥后,将它们存储在会话状态或任何位置。然后,您可以在后续的Dropbox API调用中将它们传递给node-dbox。护照的作者在GitHub上有一个很好的例子:https://github.com/jaredhanson/passport-dropbox/tree/master/examples/login

passport.use(new DropboxStrategy({
  consumerKey: DROPBOX_APP_KEY,
  consumerSecret: DROPBOX_APP_SECRET,
  callbackURL: APP_URL + '/auth/dropbox/callback'
},
function(token, tokenSecret, profile, done) {
  var user = {
    provider: 'dropbox',
    displayName: profile.displayName,
    email: profile.emails[0].value,
    // I'm choosing to store the token and tokenSecret on the user.
    // The keys must be as shown below to be compatible with node-dbox
    dboxToken: {'oauth_token': token, 'oauth_token_secret': tokenSecret}
  };

  return done(null, user);
}));


app.get('/files', function(req, res) {
  var dboxClient = dboxApp.client(req.user.dboxToken);

  dboxClient.metadata('/', {}, function(status, reply) {
    res.render('files', {
      pathMetaData: reply,
      user: req.user
    });
  });
});

答案 2 :(得分:0)

要解决该问题,您只需要应用此处提到的内容:

https://github.com/sintaxi/node-dbox/issues/3

在Oauth.js的第28行签名被编码两次。

var getSignature = function(tokenSecret){
   return encode(consumerSecret) + "&" + encode(tokenSecret)
}
var signature = encode(getSignature(secret))

将其更改为以下内容可解决无法接收oauth令牌的问题。

var signature = getSignature(secret)

THX