Hi,
I am using the dropbox core API v2 with angularJs web client using $resource and Express REST server to access dropbox. After i moved to $resource from my client instead of $http, I am getting the following CORS error when redirecting to dropbox for OAuth2 authentication as mentioned in the Dropbox OAuth2 guide.
If i enable a CORS extension for chrome, i don't get this error but the redirect does not happen.
XMLHttpRequest cannot load https://www.dropbox.com/oauth2/authorize?client_id=...&response…...&redirect_uri=https%3A%2F%2Flocalhost%3A3443%2Fcallback. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:3443' is therefore not allowed access.
(the redirect URI is valid as it works in the browser, i've modified the url pasted here to change client id and response for security reasons)
Any insight will be greatly apprecited. Here are snippets of related code:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", req.headers.origin);
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Headers","Origin, x-access-token, X-Requested-With, Content-Type, Accept, Authorization, X-CSRF-Token, Accept-Version, Content-MD5, Date, X-Api-Version, X-File-Name");
//
//res.header("Access-Control-Allow-Headers",(req.headers['access-control-request-headers']) ? req.headers['access-control-request-headers'] : "x-requested-with");
//intercepts OPTIONS method
if ('OPTIONS' === req.method) {
//respond with 200
res.sendStatus(200);
}
else {
//move on
next();
}
});and
var csrfToken = generateCSRFToken();
req.session.csrf = csrfToken;
console.log("redirecting to dropbox uri");
var redirectURl = url.format({
protocol: 'https',
hostname: 'www.dropbox.com',
pathname: 'oauth2/authorize',
query: {
client_id: APP_KEY,
response_type: 'code',
state: csrfToken,
redirect_uri: generateRedirectURI(req)
}
});
console.log("rediect uri is "+redirectURl);
res.redirect(redirectURl);
Thanks!