Home > Software engineering >  Logging in in embedded browser deprecation
Logging in in embedded browser deprecation

Time:10-08

Facebook is terminating logging in via embedded browser. I have implemented FB login using CustomRenderer in Xamarin.Forms.

In that we do not have option of LoginBehavior. So does anyone know how to handle this in Xamarin.Forms?

CodePudding user response:

The best solution is to open the login page in a CustomTab, Android offers such tabs so one does not have to call an external browser (I don't know whether Xamarin offers its own classes to use OAuth).

    public void OpenWebsiteInApp(string url)
    {
        // Use the Android custom tabs to display the webpage inside the app.
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        CustomTabsIntent customTabsIntent = builder.Build();
        customTabsIntent.LaunchUrl(_applicationContext, Uri.Parse(url));
    }

To catch the redirect from the online service, you need to implement an activity with an IntentFilter defining a DataScheme.

CodePudding user response:

Finally I have got the solution for Xamarin.Forms. I have followed this tutorial and the problem is solved.

https://evgenyzborovsky.com/2018/03/09/using-native-facebook-login-button-in-xamarin-forms/

After successful login we are getting Access_token and userid values and by using it we can get user details like First name, Last name easily.

Here is the code for the same:

var client = new System.Net.Http.HttpClient();
var url = $"https://graph.facebook.com/{facebookResponse.userId}?
fields=id,first_name,last_name,email,picture&access_token=
{facebookResponse.accessToken}";

var response = await client.GetAsync(url);

var result = response.Content.ReadAsStringAsync().Result;

var resultobject = JsonConvert.DeserializeObject<FacebookResponse>(result);            

Limitations:

  1. You can not change Login button Icon or Text properties like font and size etc.
  2. If you want to use another FB account to login you first have to logout from device's browser manually.
  • Related