I am building an app with Dropbox access, and the authorization
step is returning No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8082' is therefore not allowed access. The response had HTTP status code 400.
The app is in HTML/JQuery/Bootstrap/Cordova.
According to the documentation, I should be able to send a simple cross-site request
using contentType: 'text/plain; charset=dropbox-cors-hack'
, but am getting the above error.
The client_id
matches what is in my Dropbox/myapp App key
.
The redirect_uri
matches what is in my Dropbox/myapp Redirect URIs
.
Here is my code:
var client_id = 'matchesCodeInDropboxAppRegistration';
var response_type = 'token';
var redirect_uri = 'https://www.dropbox.com/1/oauth2/redirect_receiver';
//var csrfToken = generateCSRFToken();
var csrfToken = 'some_val'; // in process
var data = 'response_type=' + response_type + '&client_id=' + client_id + '&redirect_uri=' + redirect_uri + '&state=' + csrfToken + '&reject_cors_preflight=true';
$.ajax( {
method: 'GET',
url: 'https://www.dropbox.com/1/oauth2/authorize?' + data,
contentType: 'text/plain; charset=dropbox-cors-hack',
success: function( html ) {
$( "#db-modal-body" ).html( html );
},
error: function( jqXHR, textStatus, errorThrown ) {
console.log( "AdminDBAuthView: db_connect: fail:", textStatus, errorThrown, jqXHR );
}
} );
$( "#dropbox-connect" ).modal( "toggle" );
BTW, I tried this, and got the same result:
$( "#dropbox-connect" ).modal( {
remote: 'https://www.dropbox.com/1/oauth2/authorize?' + data,
show: true
} );
backbone.js v1.3.3 / underscore.js v1.8.3 / bootstrap v3.3.6 / JQuery v2.2.4 / cordova v6.1.1 / Node 5.10.1 / npm v3.8.6
I've been banging away at this for a while, so any help greatly appreciated.