Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

randynwalsh's avatar
randynwalsh
New member | Level 2
10 years ago

Problem and 2 possible solutions for Cordova-PhoneGap OAuth

 

The problem with Cordova / PhoneGap is that is isn't really a browser nor is it a server and to get a user oauth-authenticated requires browsing to the dropbox choser url.  So, a dropbox app must initiate an external browser (a browser on the device, but outside of phonegap, so no cross communication is possible).  The problem is that oauth authentication requires a redirect-url.  However, there is no simple redirect-url that dropbox can go back to since PhoneGap isn't a browser nor a server (ie, has no url to get back to).

 

 

Two possible solutions to this problem. One could possibly use a localhost redirect-url  and setup a static set of html files on the mobile device.  These static html files (outside of cordova) could store the access key somewhere that cordova app could pick up later.  However, this is getting increasing difficult for phonegap applications are being sandboxed, and these static files don't live in the same domain as the as the cordova app. (They live in the localhost domain not the named app domain)

 

The other solution, which I took, was to have the url-redirect go to a know internet surrogate-server.  I pass a "state" parameter in the choser request with a unique-guid.  The  surrogate server simple saves the granted access key under the unique-guid.  The Phone Gap application in the mean time is simply waiting for the user to be done with the external browser.  When done, the phonegap makes an ajax call to the surrogate-server passing the unique-guid, and getting the access key back in return.

 

Both of these solutions seam rather complicated, but I've gotten the second solution to work.  My question is, does anybody have a better answer?

 

Thanks, Randy.

2 Replies

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!