Xamarin MSAL Azure AD B2C 登录显示浏览器而不是 Web 视图

Xamarin MSAL Azure AD B2C Login shows browser instead of web view

我目前正在 Xamarin/MSAL 中使用 Azure AD B2C。

它没有问题。

但是,当调用登录方法时,它会显示浏览器而不是 Web 视图,后者的地址栏显示 URL。根据文档,它应该显示 Web 视图(客户端和服务器流)?

要使用此代码调用登录即时消息:

 AuthenticationResult ar = await App.PCA.AcquireTokenAsync(App.Scopes, GetUserByPolicy(App.PCA.Users, App.PolicySignUpSignIn), UIBehavior.ForceLogin, "ui_locales=sv", App.UiParent);

有什么方法可以强制使用网页视图而不是浏览器吗?

如您所见,您不能将登录请求强制发送到嵌入式用户代理,但这是有充分理由的。

观察到的行为与 IETF's Best Current Practice for OAuth 2.0 for Native Apps 一致:

"...当前最好的做法是在外部用户代理(通常是浏览器)中执行 OAuth 授权请求,而不是在嵌入式用户代理(例如使用 web 视图实现的用户代理)中执行。"

它进一步说:

"Encouraging users to enter credentials in an embedded user-agent without the usual address bar and visible certificate validation features that browsers have makes it impossible for the user to know if they are signing in to the legitimate site; even when they are, it trains them that it's OK to enter credentials without validating the site first."

授权服务器,例如 Google,阻止嵌入式用户代理中的 OAuth 授权请求 "for all OAuth clients on platforms where viable alternatives exist"。

目前,MSAL 中的 Xamarin Android 只能启动 Chrome 或 Chrome 自定义选项卡。我们目前正致力于在 MSAL 中包含嵌入式 webview 支持。

据我所知,MSAL 支持嵌入式 webview 如下:

await App.AuthenticationClient
                    .AcquireTokenInteractive(GlobalConstants.AzureB2C.Scopes)
                    .WithPrompt(Prompt.SelectAccount)
                    .WithUseEmbeddedWebView(true)
                    .WithParentActivityOrWindow(App.UIParent)
                    .ExecuteAsync().ConfigureAwait(false);

其中 WithUseEmbeddedWebView接受布尔值