Get user info like name, email Id etc from authentication token in .NET Backend Azure Mobile Service

Shivkanwer Singh picture Shivkanwer Singh · Sep 4, 2015 · Viewed 7.1k times · Source

I am using Azure Mobile Service to add authentication to my Windows Store app. Following this article from Mobile Services documentation I am able to get the UserId as well as MobileServiceAuthenticationToken (both for Google as well as Microsoft Account)

My question is how do I get user info like name, email Id etc. using MobileServiceAuthenticationToken in a .NET backend mobile service. I have gone through various articles explaining how this is done in Javascript Backend mobile service but couldn't find anything properly implemented in C# + .NET backend mobile service.

Any pointers appreciated.

Thanks

Answer

bot_insane picture bot_insane · Sep 4, 2015

Facebook, Google doesn't return you user profile name, e-mail when authorizing. They are giving you access token that can be used for future requests.

You need to request for example to Facebook Graph API for name, email with your MobileServiceAuthenticationToken.

You can use this library for accessing to Facebook API: https://facebookgraphapi.codeplex.com/

// MobileServiceAuthenticationToken <- your token
var facebook = new FacebookGraphAPI(MobileServiceAuthenticationToken);

// Get user profile data 
var user = facebook.GetObject("me", null);
Console.WriteLine(user["name"]);