android - 如何使用 Azure ADB2C 实现移动应用 AuthN/AuthZ?
问题描述
当前的 Azure ADB2C 移动应用示例在此处强制打开应用外部的浏览器组件,并在登录后重定向回应用。
有没有办法完全跳过这个丑陋而笨重的登录页面,直接从移动应用程序组件进行登录/注册?我想创建自己的登录,Activity
所以我只去门户网站通过 REST 获取令牌,uri
而不必在我的应用程序之外打开浏览器。
解决方案
这是一个老问题,但一年后这个问题仍然引起了我的共鸣。对此有一个答案:
.WithUseEmbeddedWebView(true)
完整的代码片段(取自 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 中,而不是打开浏览器并显示您的域名。把它放在共享代码项目中。
您不能使用自己的登录页面,但它至少看起来是您应用程序的一部分。
参考:Xamarin 注意事项
希望微软将在未来的版本中解决这个问题。
推荐阅读
- javascript - 将数据发送到谷歌电子表格
- unity3d - 我可以在新项目启动时更改默认项目设置吗?
- javascript - 使用 Node 对 Discord 机器人进行图像处理
- kaitai-struct - 将 kaitai-struct .ksy 文件转换为“漂亮”的树视图
- python - python dash核心组件动态列表
- ios - 在我将 IOS 应用程序提交到 appStore 后,AdMob 没有显示广告
- python - 使用 beautifulsoup 提取没有类或 id 的元素
- php - 基于 Woocommerce 中的运输类别的运输成本折扣
- python - Python - 更复杂函数的曲线拟合
- angular - 刷新后的Angular 6应用程序重定向到root