title: Dropbox.js authentication in Cordova/PhoneGap
body: <p>I'm writing an app in Cordova/PhoneGap which tries to fetch a file from Dropbox using Dropbox.js. Cordova version is 3.0.1 and Dropbox.js version is 0.10.0. My Javascript works just fine on a desktop browser with this:</p>
  
  <pre><code>var client = new Dropbox.Client({ key: "&lt;my key&gt;", secret: "&lt;my secret&gt;"} );
  client.authenticate(function(error, client) {
  ...
  </code></pre>
  
  <p>But in the Cordova-packaged app I get an error: "It seems the app you were using submitted a bad request".</p>
  
  <p>I suspect the problem has to do with the redirect-url which resolves to this in the Cordova app:</p>
  
  <pre><code>Dropbox.AuthDriver.BrowserBase.currentLocation()
  -&gt; file:///android_asset/www/index.html
  </code></pre>
  
  <p><em>Urls starting with file:/// will not work properly with Dropbox API even if I add them to OAuth redirect URIs in Dropbox API console.</em></p>
  
  <p>The Cordova app does work fine if I know the uid and token before:</p>
  
  <pre><code>var client = new Dropbox.Client({
      key: "&lt;my key",
      secret: "&lt;my secret&gt;",
      token: "&lt;token&gt;",
      uid: "&lt;uid&gt;"
  });
  client.authenticate(function(error, client) {
  ...
  </code></pre>
  
  <p>This way I can read my dropbox files just fine. Problem is that the token doesn't last forever and I 'd like to get a new one from my app itself. </p>
  
  <p>According to <a href="https://github.com/dropbox/dropbox-js/issues/49" rel="nofollow noreferrer">this discussion</a>, this issue should already have been resolved in an earlier version of dropbox.js (0.9.2). But I still run into it. I wonder if I should use the API a bit differently, but I don't know how. </p>
  
  <p>Dropbox.js has added a redirectUrl option <a href="https://github.com/dropbox/dropbox-js/commit/a34f8571e23a67fbd75e582186c28a4bb1a31f72" rel="nofollow noreferrer">in this commit</a> I just don't know exactly what should I put there in my Cordova app. The file:///android_asset/www/index.html will not work because Dropbox API does not allow file urls.</p>
  
  <p>Simon McDonald's answer to <a href="https://stackoverflow.com/questions/12940955/phonegap-open-external-page-and-then-go-back-to-app">this question</a> might help. But that means I have to have an external server-hosted page with the dropbox.js login functionality. Or could I use the main dropbox web login page instead?</p>