问题
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:
And my "Advanced Settings" settings:
回答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