Hi, I’ve been trying to get facebook login to work in my mobile app for 2 days.
Notice that I manage to do it in WPF application and it works, but in Xamarin.Forms there is some big problem.
This is my MainActivity in Android:
[Activity(Label = "MyAppName", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = false, NoHistory = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, LaunchMode = LaunchMode.SingleTask)]
[IntentFilter(
new[] {Intent.ActionView},
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "com.mycompany.myapp",
DataHost = "proper-host",
DataPathPrefix = "/android/com.mycompany.myapp/callback")]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
ActivityMediator.Instance.Send(intent.DataString);
}
//rest of code removed for brevity
}
Now, this is how I try to call facebook login from Xamarin application:
I have created simple interface and I just call it:
private async void fbLoginButton_Clicked(object sender, EventArgs e)
{
var loginService = DependencyService.Get<ILoginProvider>();
try
{
var loginResult = await loginService.FacebookLogin();
//it never gets here
if (loginResult.IsError)
{
Debug.WriteLine("Login error");
}
else
{
Debug.WriteLine("Login success");
}
}
catch(Exception ex) //it never gets here also
{
Debug.WriteLine("Error: " + ex.Message);
}
}
And my service in Android looks like that:
[assembly: Dependency(typeof(Xamarin.Droid.Services.AndroidLoginProvider))]
namespace Xamarin.Droid.Services
{
public class AndroidLoginProvider : ILoginProvider
{
public async Task<AuthenticationResult> FacebookLogin()
{
Auth0ClientOptions options = new Auth0ClientOptions
{
Domain = "proper-domain",
ClientId = "my-client-id"
};
Auth0Client client = new Auth0Client(options);
var result = await client.LoginAsync();
//it never gets here
if (result.IsError)
throw new InvalidOperationException();
return new AuthenticationResult();
}
}
}
So, when I call LoginAsync, the browser opens and I am able to confirm that I want to log in using facebook. After that, nothing happens. The code flow never returns from LoginAsync, nor OnNewIntent in MainActivity is called.
I think I tried everything.
Now I have: Xamarin.Forms version 5.0.0.2291
I have even installed Xamarin.Forms.AppLinks 5.0.0.2291 (because the output was saying that could not load Xamarin.Forms.AppLinks)
Auth0.OidcClient.Android: 3.2.4
Auth0.OidcClient.Core: 3.2.4
IdentityModel.OidcClient: 5.0.0
This is my output:
[NetworkSecurityConfig] No Network Security Config specified, using platform default
[Choreographer] Skipped 1196 frames! The application may be doing too much work on its main thread.
Thread started: #10
Loaded assembly: /data/data/com.mycompany.myapp/files/.override/System.Memory.dll [External]
Loaded assembly: /data/data/com.mycompany.myapp/files/.override/System.Buffers.dll [External]
Loaded assembly: /data/data/com.mycompany.myapp/files/.override/System.Numerics.Vectors.dll [External]
Loaded assembly: /data/data/com.mycompany.myapp/files/.override/System.Runtime.CompilerServices.Unsafe.dll [External]
Loaded assembly: /data/data/com.mycompany.myapp/files/.override/System.Threading.Tasks.Extensions.dll [External]
[zygote64] Checksum mismatch for dex base.apk
[EGL_emulation] eglMakeCurrent: 0x76df47e3d4a0: ver 3 1 (tinfo 0x76df47f6aac0)
[EGL_emulation] eglMakeCurrent: 0x76df47e3d4a0: ver 3 1 (tinfo 0x76df47f6aac0)
Please, help