【发布时间】:2021-11-15 15:34:47
【问题描述】:
我正在尝试通过图形 API 读取自定义属性。
使用 Azure.Identity 1.5 包和 Microsoft.Graph v4 包。
var selects = $"givenName,surName,displayName,identities,mail,mobilePhone,{B2CHelper.GetCompleteAttributeName("mfaType")},{B2CHelper.GetCompleteAttributeName("IsEnterprise")}";
var values = await _graphServiceClient.Users[id].Request()
.Select(selects)
.GetAsync();
var mfaType = values.AdditionalData[B2CHelper.GetCompleteAttributeName("mfaType")];
var isEnterprise = values.AdditionalData[B2CHelper.GetCompleteAttributeName("IsEnterprise")];
这会引发错误,说明它不在字典中。
这是我构建自定义属性的辅助函数。
internal static string GetCompleteAttributeName(string attributeName)
{
if (string.IsNullOrWhiteSpace(attributeName))
{
throw new System.ArgumentException("Parameter cannot be null", nameof(attributeName));
}
return $"extension_{_b2cExtensionAppClientId}_{attributeName}";
}
无论我从我找到的示例中尝试什么。他们不会回来。我什至不确定他们回来时的样子。我查看了附加数据,它只列出了字段。使用较新的 Azure.Identity 包真的找不到这方面的示例。
【问题讨论】:
-
您可以通过
...Request().Select("*")...获取所有用户的属性。然后检查与GetCompleteAttributeName生成的名称匹配的属性名称。 -
这不适用于自定义/扩展属性。
-
_b2cExtensionAppClientId的值是多少?您可能需要删除原始 GUID 中的连字符
标签: c# .net asp.net-core azure-ad-b2c