1

I am using angularJs with webapi and now i want to upload a file on dropbox after login in my webproject on click of a upload button.I have made an api to go the login page of dropbox and after login i want to redirect it to my own page again by redirect url.But when i am calling the webapi its giving the correct url but not redirection to the DropBox page and showing XMLHttpRequest cannot load http://localhost:3371/api/accounts/ConnectDropDown. The request was redirected to 'https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=m5e…2F%2Flocalhost%3A3371%2FHome%2FAuth&state=f50e71f99dc54e0da547d85ffbbd4764', which is disallowed for cross-origin requests that require preflight. in the console of the browser.

AngularJs:
var _connectDropbox = function () {
$http.defaults.useXDomain = true;
delete $http.defaults.headers.common['X-Requested-With'];
return $http.get(serviceBase + 'api/accounts/ConnectDropDown').then(function (results) {
return results;
});
};

WebAPi:

[Route("ConnectDropDown")]
public async Task<HttpResponseMessage> ConnectDropDown()
{
var username = User.Identity.Name;
var user = await this.AppUserManager.FindByNameAsync(username);
var appKey = ConfigurationManager.AppSettings["DropboxAppKey"];
var appSecret = ConfigurationManager.AppSettings["DropboxAppSecret"];
var ConnectState = Guid.NewGuid().ToString("N");
user.ConnectState = ConnectState;
IdentityResult addUserResult = await this.AppUserManager.UpdateAsync(user);          
var redirect = DropboxOAuth2Helper.GetAuthorizeUri(OAuthResponseType.Code, appKey,RedirectUri,ConnectState);
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = redirect;
return response;
}

Erro in Console:

4
  • here u do the redirect: var response = Request.CreateResponse(HttpStatusCode.Moved); response.Headers.Location = redirect; it's kinda normal to get the coss platform. if they didn't enable it. Have you looked over those: dropbox.com/developers/documentation/dotnet
    – Radu
    Commented Nov 25, 2015 at 7:37
  • @Radu Where from enable it? Commented Nov 25, 2015 at 7:41
  • usually they need to do this if I remember correctly.
    – Radu
    Commented Nov 25, 2015 at 8:41
  • [Cross-linking for reference: dropboxforum.com/hc/en-us/community/posts/… ]
    – Greg
    Commented Nov 27, 2015 at 18:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.