【发布时间】:2018-10-11 05:53:47
【问题描述】:
此处的当前 Azure ADB2C 移动应用程序示例强制在应用程序外部打开浏览器组件,并在登录后重定向回应用程序。
有没有办法完全跳过这个丑陋而笨重的登录页面,直接从移动应用程序组件进行登录/注册?我想创建自己的登录Activity,所以我只需要通过 REST uri 去门户获取令牌,而不必在我的应用程序之外打开浏览器。
【问题讨论】:
标签: android azure-ad-b2c
此处的当前 Azure ADB2C 移动应用程序示例强制在应用程序外部打开浏览器组件,并在登录后重定向回应用程序。
有没有办法完全跳过这个丑陋而笨重的登录页面,直接从移动应用程序组件进行登录/注册?我想创建自己的登录Activity,所以我只需要通过 REST uri 去门户获取令牌,而不必在我的应用程序之外打开浏览器。
【问题讨论】:
标签: android azure-ad-b2c
您可以创建a resource owner policy,使您能够在您的移动应用程序中收集用户凭据,然后在您的 Azure AD B2C 租户中对其进行验证。
您可以使用客户端库(例如 AppAuth for Android 或 AppAuth for iOS)为您管理策略调用。
【讨论】:
这是一个老问题,但一年后这个问题仍然引起了我的共鸣。有一个答案:
.WithUseEmbeddedWebView(true)
完整的 sn-p(取自 Azure GitHub 示例并改编)是:
async void OnLoginButtonClicked(object sender, EventArgs e)
{
AuthenticationResult result;
try
{
//bool useEmbeddedWebView = !App.IsSystemWebViewAvailable;
result = await App.AuthenticationClient
.AcquireTokenInteractive(Constants.Scopes)
.WithPrompt(Prompt.SelectAccount)
.WithParentActivityOrWindow(App.UIParent)
.WithUseEmbeddedWebView(true)
.ExecuteAsync();
await Navigation.PushAsync(new LogoutPage(result));
}
catch (MsalException ex)
{
if (ex.Message != null && ex.Message.Contains("AADB2C90118"))
{
result = await OnForgotPassword();
await Navigation.PushAsync(new LogoutPage(result));
}
else if (ex.ErrorCode != "authentication_canceled")
{
await DisplayAlert("An error has occurred", "Exception message: " + ex.Message, "Dismiss");
}
}
}
请注意,这不是一个完整的工作解决方案,但它确实会强制 B2C 模板加载到 WebView 中,而不是打开浏览器并显示您的域名。放到共享代码项目中。
您无法使用自己的登录页面,但它至少看起来是您应用的一部分。
希望 Microsoft 将在未来的版本中解决此问题。
【讨论】: