Forum Libraries, Components, and Plugins
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin Essentials - Authentication with Facebook - Android

Federico787878Federico787878 USMember ✭✭

Good morning

my aim is to integrate facebook authentication with my mobile application that i made with xamarin form.

For this purpose I followed this procedure:

https://devblogs.microsoft.com/xamarin/authentication-xamarin-essentials-aspnet/

The web api part, on the other hand, is made using NET Core 3.

I created my application from
https://developers.facebook.com/

At first I had problems with the lack of domain.

I was accessing the web api directly via the ip address and without https and this gave me problems.

Now I have fixed these problems but it is not clear how the return callback should be handled.

I did as written in the documentation

 var callbackUrl = new Uri ("myapp://");
 r = await WebAuthenticator.AuthenticateAsync (authUrl, callbackUrl);

Actually this callBackurl is IGNORED and the url that is called is the default callback url which is:
https://www.mywebapi.eu/signin-facebook?code=xxxxxxx

This page is not present in my web api project and therefore it all ends with a sad 404 error.

in the example it is not clear if a signin-facebook control should be created.

I would have expected the callback to call my app again and have permission to read the necessary user information.

async Task OnAuthenticate(string scheme)
{
    try
    {
        WebAuthenticatorResult r = null;

        if (scheme.Equals("Apple")
            && DeviceInfo.Platform == DevicePlatform.iOS
            && DeviceInfo.Version.Major >= 13)
        {
            r = await AppleSignInAuthenticator.AuthenticateAsync();
        }
        else
        {
            var authUrl = new Uri(authenticationUrl + scheme);
            var callbackUrl = new Uri("myapp://");

            r = await WebAuthenticator.AuthenticateAsync(authUrl, callbackUrl);
        }

        AuthToken = r?.AccessToken ?? r?.IdToken;
    }
    catch (Exception ex)
    {
        AuthToken = string.Empty;
        await DisplayAlertAsync($"Failed: {ex.Message}");
    }
}
Sign In or Register to comment.