Xamarin Android 系统浏览器的 MSAL.NET 使用注意事项Xamarin Android system browser considerations for using MSAL.NET

本文介绍将 Xamarin Android 上的系统浏览器与适用于 .NET 的 Microsoft 身份验证库 (MSAL.NET) 配合使用时的注意事项。This article discusses what you should consider when you use the system browser on Xamarin Android with the Microsoft Authentication Library for .NET (MSAL.NET).

从 MSAL.NET 2.4.0 预览版开始,MSAL.NET 支持除 Chrome 之外的浏览器。Starting with MSAL.NET 2.4.0 Preview, MSAL.NET supports browsers other than Chrome. 它不再要求在 Android 设备上安装 Chrome 进行身份验证。It no longer requires Chrome be installed on the Android device for authentication.

建议使用支持自定义标签页的浏览器。We recommend that you use browsers that support custom tabs. 下面是这些浏览器的一些示例:Here are some examples of these browsers:

提供自定义标签页支持的浏览器Browsers that have custom tabs support 包名称Package name
ChromeChrome com.android.chromecom.android.chrome
Microsoft EdgeMicrosoft Edge com.microsoft.emmxcom.microsoft.emmx
FirefoxFirefox org.mozilla.firefoxorg.mozilla.firefox
EcosiaEcosia com.ecosia.androidcom.ecosia.android
KiwiKiwi com.kiwibrowser.browsercom.kiwibrowser.browser
BraveBrave com.brave.browsercom.brave.browser

除了标识提供自定义标签页支持的浏览器之外,我们的测试还表明,一些不支持自定义标签页的浏览器也适用于身份验证。In addition to identifying browsers that offer custom tabs support, our testing indicates that a few browsers that don't support custom tabs also work for authentication. 这些浏览器包括 Opera、Opera Mini、InBrowser 和 Maxthon。These browsers include Opera, Opera Mini, InBrowser, and Maxthon.

测试的设备和浏览器Tested devices and browsers

下表列出了经过身份验证兼容性测试的设备和浏览器。The following table lists the devices and browsers that have been tested for authentication compatibility.

设备Device 浏览者Browser 结果Result
Huawei/One+Huawei/One+ Chrome*Chrome* 通过Pass
Huawei/One+Huawei/One+ Edge*Edge* 通过Pass
Huawei/One+Huawei/One+ Firefox*Firefox* 通过Pass
Huawei/One+Huawei/One+ Brave*Brave* 通过Pass
One+One+ Ecosia*Ecosia* 通过Pass
One+One+ Kiwi*Kiwi* 通过Pass
Huawei/One+Huawei/One+ OperaOpera 通过Pass
HuaweiHuawei OperaMiniOperaMini 通过Pass
Huawei/One+Huawei/One+ InBrowserInBrowser 通过Pass
One+One+ MaxthonMaxthon 通过Pass
Huawei/One+Huawei/One+ DuckDuckGoDuckDuckGo 用户已取消身份验证User canceled authentication
Huawei/One+Huawei/One+ UC 浏览器UC Browser 用户已取消身份验证User canceled authentication
One+One+ DolphinDolphin 用户已取消身份验证User canceled authentication
One+One+ CM 浏览器CM Browser 用户已取消身份验证User canceled authentication
Huawei/One+Huawei/One+ 未安装任何内容None installed AndroidActivityNotFound exceptionAndroidActivityNotFound exception

* 支持自定义标签页* Supports custom tabs

已知问题Known issues

如果用户未在设备上启用浏览器,MSAL.NET 会引发 AndroidActivityNotFound 异常。If the user has no browser enabled on the device, MSAL.NET will throw an AndroidActivityNotFound exception.

  • 缓解措施:要求用户在其设备上启用浏览器。Mitigation: Ask the user to enable a browser on their device. 建议使用支持自定义标签页的浏览器。Recommend a browser that supports custom tabs.

如果身份验证失败(例如,如果身份验证在启动时使用了 DuckDuckGo),MSAL.NET 会返回 AuthenticationCanceled MsalClientExceptionIf authentication fails (for example, if authentication launches with DuckDuckGo), MSAL.NET will return AuthenticationCanceled MsalClientException.

  • 根本问题:未在设备上启用支持自定义标签页的浏览器。Root problem: A browser that supports custom tabs wasn't enabled on the device. 使用无法完成身份验证的浏览器启动了身份验证。Authentication launched with a browser that couldn't complete authentication.
  • 缓解措施:要求用户在其设备上启用浏览器。Mitigation: Ask the user to enable a browser on their device. 建议使用支持自定义标签页的浏览器。Recommend a browser that supports custom tabs.

后续步骤Next steps

有关详细信息和代码示例,请参阅在 Xamarin Android 上的嵌入式 Web 浏览器与系统浏览器之间选择嵌入式 Web UI 与系统 Web UIFor more information and code examples, see Choosing between an embedded web browser and a system browser on Xamarin Android and Embedded versus system web UI.