Vesa Vainio
Vesa Vainio

Reputation: 171

'Not a whitelisted origin' error with Azure Mobile Services Authentication

I'm trying to create a demo site using Azure Mobile Services. I started with the HTML/JavaScript sample app available in the Mobile Services portal. I added the authentication exactly as explained in the documentation.

When the JavaScript on my index.html page is trying to authenticate against Facebook, I get a new browser window that shows the following error: {"code":401,"error":"Error: Not a whitelisted origin: https://mysite.azurewebsites.net"}

The address bar for this error window is the following: https://mysite.azure-mobile.net/login/facebook?completion_type=postMessage&completion_origin=https%3A%2F%2Fmysite.azurewebsites.net

The line of client-side JavaScript where the execution is going when this happens is the following:

function logIn() {
    client.login("facebook").then(refreshAuthDisplay, function (error) {
        alert(error);
    });
}

I think I have done everything according to the tutorial, and set up the facebook app correctly.

I peculiar thing is that I think this problem is transient. Sometimes it happens and sometimes it doesn't. When it's happening, it doesn't matter how many times I try in succession, it never works. However, at some point, I got the authentication in my demo app working as it should, and was happy. After a couple of days, I return to working with this demo app without touching anything in the meanwhile, and suddenly I get this error.

From the URL giving the error message it seems that this error comes from the Mobile Services in Azure itself. It's not coming from my app, and it's not coming from Facebook.

Any help in solving this is much appreciated!

Upvotes: 3

Views: 578

Answers (1)

carlosfigueira
carlosfigueira

Reputation: 87238

To make sure that your mobile service can be accessed from web sites deployed on different domains, you need to add your host in the cross-origin resource sharing (cors) session in the configure page in the Azure Mobile Services portal.

Upvotes: 3

Related Questions