dropbox.js,未执行的成功登录代码

时间:2013-04-23 13:53:54

标签: javascript oauth dropbox

所以我正在玩dropbox.js。在github上的入门指南中,用于登录的代码段是:

client.authenticate(function(error, client) {
  if (error) {
    // Replace with a call to your own error-handling code.
    //
    // Don't forget to return from the callback, so you don't execute the code
    // that assumes everything went well.
    return showError(error);
  }

  // Replace with a call to your own application code.
  //
  // The user authorized your app, and everything went well.
  // client is a Dropbox.Client instance that you can use to make API calls.
  doSomethingCool(client);
});

背景:我正在使用Dropbox.Drivers.Redirect驱动程序,因此在调用client.authenticate()时,用户会被带到Dropbox登录页面,登录,授权我的应用程序,然后重定向回到页面整个过程从。

开始

然而,在登录Dropbox并重定向回我的页面后,我的doSomethingCool()方法(或者实际上,传递给authenticate()的回调的任何部分)完全被忽略。

但是,如果用户已经在调用authenticate()时登录到Dropbox,则dropbox.js不会将它们转移到dropbox.com(我猜它只是在内部验证当前会话有效),但回调(和doSomethingCool())确实执行了!

我想要做的实际情况是:在我的页面上,用户正在选择一种支持webapp存储的方法。一旦他们登录到Dropbox并将他们重定向回我的页面,我实际上希望他们转到应用程序的主要部分,而不是这个小选择器屏幕。在dropbox登录后似乎没有一种方法可以指定不同的返回地址,所以我打算在authenticate()的回调中使用window.location.replace手动完成。但它不起作用:(

一种替代方法是在调用client.authenticate()之前使用AJAX向我的域发送标志,以指示用户在OAuth流中。然后当我的服务器再次请求我的选择器屏幕时(通过Dropbox登录后的重定向),执行自动重定向到主应用程序。但它有点乱(不是吗?)

0 个答案:

没有答案