5

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

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

var oAuthLoginPresenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
oAuthLoginPresenter.Login(App.OAuth2Authenticator);

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

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

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

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

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

在我获取重定向的拦截活动中,如下所示:

[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();
    }
}

我是否错过了关闭该演示者的步骤?请问还有什么想法吗?

更新:

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

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

4

1 回答 1

0

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

//don't show warning message when closing account selection page
CustomTabsConfiguration.CustomTabsClosingMessage = null;
于 2018-05-15T07:44:51.410 回答