xamarin/Sport

Native Authentication

Closed this issue · 7 comments

Hi Team,

Not sure if this is the right place to bring this up. Is there a reason you do not have any samples that would use Native authentication?

I am new to Xamarin. And I do think that if I have an android phone, majority of time a user will have a google account, why would you want user to enter credentials again?

Can you not just use existing identity already on the phone? If so can you at-least have a sample or implement it in your samples?

Thank you

This specific sample is about sharing common code across multiple OS. iOS does not support a "system Google account" that other apps can use for authentication.

Was there any specific reason to not use Xamarin.Auth but rather have a kind of custom implementation for Google Login? Do you expect any issues replacing it with Xamarin.Auth and using also Facebook, Twitter, etc.?

In order to secure the Azure backend against unauthenticated calls, I had to use the Azure-sanctioned APIs to authenticate in order to generate an Azure auth token.

If you're not using Azure on the backend, you can authenticate in whatever manner you choose.

Ok I see, so using OAuth would not be saving our backend. Following your point, I tried to add Facebook, on the backend as well as on the App (I followed the Azure docs here and here).

My Backend now has following new route:

        public async Task<FacebookCredentials> GetUserIdentityFacebook()
        {
            ServiceUser serviceUser = User as ServiceUser;
            if (serviceUser != null)
            {
                var identity = await serviceUser.GetIdentitiesAsync();
                var credentials = identity.OfType<FacebookCredentials>().FirstOrDefault();
                return credentials;
            }
            return null;
        }

and my App has the following calls:

  1. DisplayWebView() in Authentication.cs on iOS/Android:
    return await AzureService.Instance.Client.LoginAsync(Forms.Context, MobileServiceAuthenticationProvider.Facebook);
  2. ShowGoogleAuthenticationView() in AuthenticationViewModel.cs
    var identity = await AzureService.Instance.Client.InvokeApiAsync("getUserIdentityFacebook", null, HttpMethod.Get, null);

Starting the App it is trying to load the Facebook Login Page, but it is showing an error "Not Logged In: You are not logged in. Please login and try again."

I don't know if I'm missing anything here. I tried a lot getting this running with Facebook but I'm stuck right now. I got this working with Twitter.

Any help is highly appreciated! Thank you a lot in advance.

I'm no Azure expert so I unfortunately cannot advise. I'd hit up the Azue forums or give StackOverflow a try.

I've found wrong setting in Facebook and it works now. App supports FB, Twitter & Google now. I'm happy to share my code if you are interested. Maybe its worth considering it for the upcoming version.

I would be interested in seeing this code, if you are still willing to share it? Thanks