azure-ad-b2c - 在 Android 中使用 MSAL 时如何从 IAuthenticationResult 获取 B2CUser
问题描述
我在 B2C 多用户模式下将 MSAL 与 Android 一起使用。我下面的代码来自这个例子。它显示了如何从帐户列表中获取 B2CUsers 列表:
private void loadAccounts() {
if (b2cApp == null) {
return;
}
b2cApp.getAccounts(new IPublicClientApplication.LoadAccountsCallback() {
@Override
public void onTaskCompleted(final List<IAccount> result) {
users = B2CUser.getB2CUsersFromAccountList(result);
updateUI(users);
}
@Override
public void onError(MsalException exception) {
displayError(exception);
}
});
}
但我还需要在认证后获取特定的 B2CUser:
AcquireTokenParameters parameters = new AcquireTokenParameters.Builder()
.startAuthorizationFromActivity(getActivity())
.fromAuthority(B2CConfiguration.getAuthorityFromPolicyName(policyListSpinner.getSelectedItem().toString()))
.withScopes(B2CConfiguration.getScopes())
.withPrompt(Prompt.LOGIN)
.withCallback(getAuthInteractiveCallback())
.build();
b2cApp.acquireToken(parameters);
在 authenticationResult 之后给了我一个 IAccount:
@Override
public void onSuccess(IAuthenticationResult authenticationResult) {
/* Successfully got a token, use it to call a protected resource - MSGraph */
Log.d(TAG, "Successfully authenticated");
/* display result info */
displayResult(authenticationResult);
/* Reload account asynchronously to get the up-to-date list. */
loadAccounts();
}
但我似乎无法将其转换为 B2CUser 或从中获取 ID:
iAuthenticationResult.getAccount().getId()
似乎返回附加到它的策略,我也无法获得 displayName。
解决方案
推荐阅读
- java - 如何在使用 maven 构建的 Java 项目中编译 spark-testing-base?
- vector - Rust 中的 Vec<(i64, i64)> 数据类型是什么?
- discord.py - 高效格式化 discord.py
- c++-cli - 静态库中的 C++/CLI fstream 阻止 winform 程序运行
- python - Python 代码但不能使用 max 和 min 函数
- python - 在 Azure 上使用 Celery 部署烧瓶
- r - 遍历 R 数据框对象并添加一列
- reactjs - 使用 querySnapshot.size 作为带有 firebase 和 reactjs 的 .doc id
- python - 计算连续的 NaN 值并获取 NaN 连续周期的开始日期和结束日期
- selenium - 如何在 Pytest JUNIT xml 中附加屏幕截图以显示在 Azure DevOps 上?