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

故事扮演 提交于 2021-02-08 05:44:24

问题


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?

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


回答1:


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();
};



回答2:


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.



来源:https://stackoverflow.com/questions/45237177/authentication-error-e-message-oauth-error-permissionserror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!