Azure Mobile Apps and Facebook integration — not as straightforward as it seems

Vuong Le Phong
dtlpub
Published in
3 min readMay 8, 2017

My team at Digital Transformation Ltd are working on an exciting new project called Grub. For our mobile application we’ve opted to use Xamarin Forms and Azure Mobile Apps. My colleague Tristan Dashwood was tasked to implement Facebook integration for the app. I told him it should be easy with Azure Mobile Apps. How hard could it be, right?

Our plan is to follow the below documentation written by Microsoft:

https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-how-to-configure-facebook-authentication

https://developer.xamarin.com/guides/xamarin-forms/cloud-services/authentication/azure/

Tristan is a very smart cookie so he got it working after a couple of hours. “This is too good to be true”, I thought to myself.

My instinct was right. The initial authentication was indeed straightforward, but gathering the user’s information was another matter altogether. It took a few technical hurdles and a lot of trawling through blog posts to figure out how to get additional user information from Facebook Graph API such as email, first name and last name.

There’s always a relevant XKCD

Most of us in I.T. have a Master’s degree in Googling, but I must say, after this I’m about ready to pick up my PhD. A quick Google search revealed a myriad of ways in which to tackle this requirement, however, none of them worked, most of them had become obsolete with the latest APIs.

For example, Azure Mobile Services used to have a function getIdentities() returning an object with provider-specific data, which is then used to query their user information, but this method no longer exists.

I felt bad for bombarding Tristan with suggested solutions I found from Google and I could see that he lost a few hairs trying to implement what I suggested.

We were about to give up until I decided to do some more reading on Azure documentation and I found this:

Your application can also obtain additional user details through an HTTP GET on the /.auth/me endpoint of your application. A valid token that's included with the request will return a JSON payload with details about the provider that's being used, the underlying provider token, and some other user information. The Mobile Apps server SDKs provide helper methods to work with this data
https://docs.microsoft.com/en-us/azure/app-service/app-service-authentication-overview

Again I had found a promising looking solution, but unfortunately this too was a dead end; the Mobile Apps no longer has the GetAppServiceIdentityAsync() method. However, it is still true that user details can be obtained through an HTTP GET on the /.auth/me endpoint. We managed to get it working with the following code:

var client = new HttpClient();

client.DefaultRequestHeaders.Add(“X-ZUMO-AUTH”, user.MobileServiceAuthenticationToken);

var response = await client.GetAsync(Constants.ApplicationURL + “/.auth/me”);

if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
}

The task at hand was relatively simple, authentication and user information retrieval using Azure Mobile Apps and Facebook. While ultimately successful, wading through a sea of outdated documentation and blog posts to find a working example was very time intensive.

In summary, we need to anticipate hurdles like this in the project plan, especially when working with cloud platforms and the latest tech. More importantly, make sure that you pick a vendor like us who has hands-on experience with these technologies and know what they are doing.

If it sounds too good to be true, it probably is

That’s it for now.

www.digitaltransformation.co.nz

--

--

Vuong Le Phong
dtlpub
Writer for

An experienced Solutions Architect and Practice Lead who has had 15 years’ experience in the area of Solution Architecture, Design and Development.