Xamarin.Auth Facebook login Completed event not firing

最后都变了- 提交于 2021-01-29 13:16:47

问题


I am trying to create a Xamarin.Forms application with a Facebook login button. Everything works up until the part where the Completed event, which never gets fired.

I am using a PageRenderer to initiate the auth flow as follows:

[assembly: ExportRenderer(typeof(Page1), typeof(LoginPageRenderer))]
namespace xmrn1.Droid {
    class LoginPageRenderer : PageRenderer {
        private const string ClientId = "<sanitized>";

        public LoginPageRenderer(Context ctx) : base(ctx) { }

        protected override void OnElementChanged(ElementChangedEventArgs<Page> e) {
            base.OnElementChanged(e);

            var authorizeUri = new Uri("https://www.facebook.com/dialog/oauth/");
            var redirectUri = new Uri($"fb{ClientId}://authorize");
            var auth = new OAuth2Authenticator(
                ClientId,
                "email",
                authorizeUri,
                redirectUri);

            auth.Completed += Auth_Completed;
            var ui = auth.GetUI(Context);
            Context.StartActivity(ui);
        }

        private void Auth_Completed(object sender, AuthenticatorCompletedEventArgs e) {
            // This never gets called
        }
    }
}

And this is my "Facebook Login" settings:

Imgur

And my "Advanced Settings" settings:

Imgur


回答1:


Found the answer, I had to turn on the Web OAuth Login in the Facebook Login settings, and also to change the redirectUri to some uri in my domain, and add that uri to the Valid OAuth Redirect URIs in that same settings window.

Strange thing though, now when I log in, and the two-factor-authentication code prompt shows up, my phone displays an authenticator popup notification asking me to approve and when I press "Yes" it doesn't automatically confirm the login, I have to manually type the 2fa code anyway...



来源:https://stackoverflow.com/questions/53822377/xamarin-auth-facebook-login-completed-event-not-firing

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