Azure Mobile Services backend serviceUser does not return Facebook identities as expected

ossentooossentoo GBMember ✭✭
edited November 2015 in Xamarin.Forms


I'm struggling with a Xamarin/Azure Mobile Services/Facebook issue that I don't know how to resolve. What I'm trying to do is login to Facebook for a user and then save that user's details to a service side database via AMS custom controller. I am running Azure Mobile Services on the backend.

What I have in place is the code below that successfully logs in a Facebook user.

var fbUser = await DependencyService.Get<IMobileClient>().LoginAsync(MobileServiceAuthenticationProvider.Facebook);
var dtm = DateTime.UtcNow;

I then want to save fbUser to the database where I'm using ASP.NET Identity tables all configured. I want to use this user to gain access to the facebook user's profile information. I therefore have a backend custom controller action that looks like this:

        public async Task<IHttpActionResult> LoginToFacebook(MobileServiceUser msUser)
                if (msUser != null)
                    var serviceUser = User as ServiceUser;
                    var identities = await serviceUser.GetIdentitiesAsync();

                    var result = new JObject();
                    var fb = identities.OfType<FacebookCredentials>().FirstOrDefault();

                    if (fb == null)
                        return NotFound();

                    var googleCredentials = identities.OfType<GoogleCredentials>().FirstOrDefault();
                    var azure = identities.OfType<MicrosoftAccountCredentials>().FirstOrDefault();

                    var accessToken = fb.AccessToken;
                        await GetProviderInfo("" + accessToken));

                    var email = GetUserInfo(result);
                    var userTypeId = UTypes.Facebook;

When debugging on the backend side, the MobileServiceUser is a valid object and I can check the token and Facebook userid which are the same as were created on the client. However, the highlighted line returns zero identities. This means that fb variable end up being null.

The question is, why are no identities being returned from the serviceUser variable above?



Sign In or Register to comment.