首页 > 解决方案 > 谷歌登录页面不会在秋季关闭 - xamarin

问题描述

这种方法工作正常,但唯一的问题是用户输入谷歌电子邮件和密码后,它不会回到HomePage应用程序中。用户必须手动点击关闭按钮,然后才能HomePage进入应用程序内部

我在网上找到了类似的代码,它们似乎都有相同的东西。不知道我错过了什么

async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
{
    var authenticator = sender as OAuth2Authenticator;
    if (authenticator != null)
    {
        authenticator.Completed -= OnAuthCompleted;
        authenticator.Error -= OnAuthError;
    }

    User user = null;
    if (e.IsAuthenticated)
    {
        var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account);
        var response = await request.GetResponseAsync();
        if (response != null)
        {
            string userJson = await response.GetResponseTextAsync();
            user = JsonConvert.DeserializeObject<User>(userJson);
        }

        if (user != null)
        {
             store.Delete(account, Constants.AppName);
            var route = $"{ nameof(HomePage)}";
            await Shell.Current.GoToAsync(route);
        }

        await store.SaveAsync(account = e.Account, Constants.AppName);
    }
}//end of method

安卓项目

[Activity(Label = "CustomUrlSchemeInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(
new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataSchemes = new[] { "com.googleusercontent.apps.59233251-abcd" },
DataPath = "/oauth2redirect")]
public class CustomUrlSchemeInterceptorActivity : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Convert Android.Net.Url to Uri
        var uri = new Uri(Intent.Data.ToString());

        // Load redirectUrl page
        AuthenticationState.Authenticator.OnPageLoading(uri);

        Finish();
    }
}

标签: c#androidxamarinxamarin.formsxamarin.android

解决方案


推荐阅读