0

我正在使用 Xamarin.Android 开发一个应用程序,并且我需要登录系统。因此我使用 Xamarin.Auth。我创建了一个 OAuth2Authenticator 但不工作 auth.completed 。fire auth.completed 如何成功?

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

1 回答 1

0

在 1.4.x 版本之前,Xamarin.Auth 需要真实(现有)端点,它试图将其加载到嵌入式 WebView 中,所以您的问题是:

redirectUrl: new Uri("ex/callback")

你需要类似http://somehost.top.level.domain的东西。注意: localhost 不适用于旧版本的 Xamarin.Auth。

自 1.4.0 版以来,其中一些限制已被删除,并且允许使用自定义方案的 redirect_url。

于 2017-05-11T08:22:28.993 回答