Xamarin.Auth Google Presenter 未在 Android Xamarin.Forms 应用程序中关闭

loa*_*ger 5 xamarin.android oauth-2.0 xamarin.auth xamarin.forms

我正在使用 Xamarin.Form 编写一个 Android 应用程序。我已经成功实现了 OAuth,我可以使用 OAuth2Authenticator 登录并获取用户信息。

当用户单击注册/登录时,我会显示 OAuthLoginPresenter,如下所示:

var oAuthLoginPresenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
oAuthLoginPresenter.Login(App.OAuth2Authenticator);
Run Code Online (Sandbox Code Playgroud)

这很好用,用户会看到登录页面。

当用户单击 OAuth2Authenticator 实例上的“允许完成的事件”时,会按预期触发,并且用户再次返回查看应用程序。

然而,这就是我的问题所在 - 我收到一条通知:

如果 CustomTabs 登录屏幕未关闭,则通过导航回应用程序自动关闭 CustomTabs。

事情是虽然我回到了应用程序。如果我查看所有打开的应用程序,我可以看到登录屏幕仍在后台运行,因此演示者尚未关闭。

在我的拦截 Activity 中,它获得了重定向,如下所示:

[Activity(Label = "GoogleAuthInterceptor")]
[IntentFilter
(
    actions: new[] { Intent.ActionView },
    Categories = new[]
    {
            Intent.CategoryDefault,
            Intent.CategoryBrowsable
    },
    DataSchemes = new[]
    {
        // First part of the redirect url (Package name)
        "com.myapp.platform"
    },
    DataPaths = new[]
    {
        // Second part of the redirect url (Path)
        "/oauth2redirect"
    }
)]

public class GoogleAuthInterceptor: Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your application here
        Android.Net.Uri uri_android = Intent.Data;

        // Convert Android Url to C#/netxf/BCL System.Uri
        Uri uri_netfx = new Uri(uri_android.ToString());

        // Send the URI to the Authenticator for continuation
        App.OAuth2Authenticator?.OnPageLoading(uri_netfx);

        Finish();
    }
}
Run Code Online (Sandbox Code Playgroud)

我在这里错过了关闭演示者的步骤吗?请问还有其他想法吗?

更新:

我现在发现使用 Chrome 作为默认浏览器工作正常并且演示者已关闭。但是如果我使用三星浏览器作为我的默认浏览器 - 它不会关闭。

所以我需要一种方法来手动关闭它。

ant*_*err 1

只需在主要活动中初始化 Xamarin.Auth 时将属性设置为 null:

//don't show warning message when closing account selection page
CustomTabsConfiguration.CustomTabsClosingMessage = null;
Run Code Online (Sandbox Code Playgroud)