Nader
Nader

Reputation: 152

Using the Azure Mobile Apps JavaScript Client in browser to access Authenticated Tables

I am following the tutorial for azure mobile app services here.

The authentication works fine when using Cordova azure client. However, on the browser, I get the error below in chrome console:

XMLHttpRequest cannot load http://MYAPP.azurewebsites.net/tables/Users?. 
The request was redirected to 'https://MYAPP.azurewebsites.net/tables/Users?', 
which is disallowed for cross-origin requests that require preflight.

A workaround is to run chrome with --disable-web-security flag. However, I wonder if there is a way to fix this issue.

I have set CORS in azure portal to * which I assume allows all origins

Upvotes: 1

Views: 78

Answers (1)

Dale Anderson
Dale Anderson

Reputation: 1701

You need to configure the CORS settings in the portal to allow the domain of the host that the web server is hosted on. For example, if you're entering something like https://www.mywebsite.com/ into the address bar to hit your Mobile App, you need to add www.mywebsite.com into the CORS settings.

I also notice the request is being redirected from http to https. Azure requires https for any authenticated requests (to protect the JWT token from man in the middle attacks) and will redirect if the request is on http. You need to change the URL in the constructor for your Mobile Apps client to use HTTPS.

Upvotes: 2

Related Questions