TomKel Grove
TomKel Grove

Reputation: 41

How to Authenticate users on azure mobile services from Windows Phone 8 using HTML?

I am experimenting with azure mobile services and have implemented the authentication example here. This works on most devices ( iOs, IE9 and chrome on desktop, IE10 Surface RT, android ) but on a WP8 device ( a Nokia 920, to be precise ) it returns

"Cannot reach window opener. It may be on a different Internet Explorer zone"

after attempting to return from the authenication providers pop-up. This is mentioned briefly in the link above, but only wrt to connecting to the service from localhost. This is not the case here and other devices work fine. It does not seem to be a problem with any particular authentication provider - all ( facebook, google, twitter, windows connect ) return the same message. And as these other devices work, it seems unlikely that the service is mis-configured, but there could very well be something subtle that I'm missing.

Upvotes: 4

Views: 755

Answers (1)

Vesa Vainio
Vesa Vainio

Reputation: 21

The way I got the authentication to work is not to use Facebook JavaScript SDK, but another flow, described here https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/#step2

For handling the response when I get the redirect back from Facebook, I used the following code:

function handleLoginResponse() {
    var frag = $.deparam.fragment();
    if (frag.hasOwnProperty("access_token")) {
        client.login("facebook", { access_token: frag.access_token }).then(
        function () {
            // do your thing when logged in
        }, function (error) {
            alert(error);
        });
    }
}

This code makes use of jQuery BBQ plugin, found here http://benalman.com/projects/jquery-bbq-plugin/.

This way I can get Facebook auth to work on WP8 and I'm able to pass the access token to Mobile Services login.

A slight problem is that now the access token sticks in my site URL, which I think is a problem if the user decides to share the URL, for example. I think I can get around this by e.g. putting the info in a cookie (or local storage) and then redirecting to the plain URL of my site.

Upvotes: 1

Related Questions