2

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

tedi
  • 6,350
  • 5
  • 52
  • 67
  • I think you need to handle 'redirect' events. At least that's what I understand from some of the documentation. Also it might be a good idea to show a snippet of code, to show us how your calling and handling this from your PCL. – JoeTomks Jul 21 '17 at 12:18
  • @Digitalsa1nt handle redirect event how? I can't redirect back to my application as it's not a web application. Or do i have to redirect elsewhere? – tedi Jul 21 '17 at 12:26
  • 1
    So the 'not now' redirects to an error page, which invokes 'auth.error' – JoeTomks Jul 21 '17 at 12:28

2 Answers2

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();
};
Polyariz
  • 534
  • 1
  • 7
  • 17
0

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.

JoeTomks
  • 3,243
  • 1
  • 18
  • 42
  • There is no property "IsEnabled" in "Xamarin.Auth" nuget package version 1.5.0.3. – tedi Jul 24 '17 at 06:28
  • is there a ShowErrors property on the OAuth2Authenticator ? – JoeTomks Jul 24 '17 at 08:21
  • There is. But i wasn't using it before, now i do. It's working on iOS now (at least something :>). But Android is still the same. I have updated my question, added some more code if it will help. I can't figure out how to close the "embeded browser" on android. It opens an external http URL. – tedi Jul 24 '17 at 12:19