我正在用Xamarin.Android开发一个应用程序,我需要登录系统。因此,我使用Xamarin.Auth。我创建了一个OAuth2Authenticator,但没有工作的auth.completed。fire auth.completed on是如何成功的?
public void LoginToSabis()
{
var auth = new OAuth2Authenticator(
clientId: "example_android",
scope: "read",
authorizeUrl: new Uri("example/authorize"),
redirectUrl: new Uri("ex/callback"));
auth.AllowCancel = true;
// If authorization succeeds or is canceled, .Completed will be fired. BUT WHEN SUCCEEDS NOT WORKING, WHEN CANCELED WORKING...
auth.Completed += async (s, ee) =>
{
if (!ee.IsAuthenticated)
{
var builder = new Android.Support.V7.App.AlertDialog.Builder(this);
builder.SetMessage("Not Authenticated");
builder.SetPositiveButton("Ok", (o, e) => { });
builder.Create().Show();
return;
}
AccountStore.Create(Application.Context).Save(ee.Account, "cg");
StartActivity(typeof(LoginRedirectActivity));
};
}发布于 2017-05-11 16:22:29
在1.4.x之前的版本中,Xamarin.Auth需要真实(现有)端点,并尝试将其加载到嵌入式WebView中,因此您的问题是:
redirectUrl: new Uri("ex/callback")
你需要像http://somehost.top.level.domain这样的东西。注意:本地主机不能与旧版本的Xamarin.Auth一起工作。
从版本1.4.0起,其中一些限制被删除,并允许使用自定义方案的redirect_url。
https://stackoverflow.com/questions/39364844
复制相似问题