skip to Main Content

I’m using Xamarin.Auth version 1.5.0.3 in my xamarin.android and xamarin.ios (PCL) project for application authentication/login with facebook’s OAuth API. The issue arises after I click on the “Not now” link (watch the screenshot below). I get the following error dialog:

Authentication Error e.Message = OAuth Error = Permissions+error

Is there any way to disable this link or to fix it somehow? Or does someone have an idea why this happens?

enter image description here

enter image description here

iOS code (which works now):

public override void ViewDidAppear(bool animated)
{
    base.ViewDidAppear(animated);

    var auth = new OAuth2Authenticator(
        clientId: "myClientId",
        scope: "",
        authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"),
        redirectUrl: new Uri("https://www.facebook.com/connect/login_success.html"),
        isUsingNativeUI: true
    );

    auth.Completed += (sender, eventArgs) =>
    {
        if (eventArgs.IsAuthenticated)
        {

        }
        else
        {

        }
    };

    var errorWasAlreadyTrown = false;
    auth.Error += (object sender, AuthenticatorErrorEventArgs eventArgs) =>
        {
                if (!errorWasAlreadyTrown)
                {
                    OAuth2Authenticator auth2 = (OAuth2Authenticator)sender;
                    auth2.ShowErrors = false;

                    App.SuccessfulLoginAction.Invoke();
                    errorWasAlreadyTrown = true;
                }
        };

    PresentViewController(auth.GetUI(), true, null);
}

But it still doesn’t work on Android. All the code is the same, except on iOS i override the “ViewDidAppear” method and on android the “OnElementChanged” method. And at the end i call “PresentViewController” on iOS and “activity.StartActivity” on Android.

I followed some instructions here: How to login to facebook in Xamarin.Forms

2

Answers


  1. It’s hard for me to accurately assimilate this into your code as there’s none to go off, but one of the things that you can try is to handle the auth.error event.

    auth.Error += (object sender, AuthenticatorErrorEventArgs eventArgs) => {
        auth.IsEnabled = false;
    };
    

    There is a discussion in a xamarin developer thread that can be found here, that might be useful to you.

    Login or Signup to reply.
  2. When the “Not now” link clicked, there is the method to hide dialog with error:

    auth.Error += (sender, eventArgs) =>
    {
      OAuth2Authenticator auth2 = (OAuth2Authenticator)sender;
      auth2.ShowErrors = false;
      auth2.OnCancelled();
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search