我添加了自定义 Organization
字段作为我的 Azure Active Directory B2C 租户中的用户属性,如下所示:
我正在使用 Microsoft Graph .NET Client Library管理 Azure Active Directory B2C 中的用户,并想使用类似于以下代码的内容来设置用户的自定义 Organization
字段和用户的内置 Email Addresses
field 。
await graphClient.Users[user.Id].Request().UpdateAsync(new User()
{
Email Addresses = new StringCollection("myemail@mydomain.com")
Organization = "Microsoft"
});
两个问题:
Email Addresses
? Organization
? 本文档显示 how to create a custom attribute但没有说明如何使用 Graph Client 访问或使用该属性。
本文档展示了如何 create custom attributes and edit the Relying Party (RP) file .
有更容易的方法吗?什么是
graphClient
然后获取/设置这些自定义用户属性的代码?
最佳答案
Microsoft Graph API 以及 Microsoft Graph 客户端是否支持向 Azure AD B2C 租户注册的扩展属性,这有点令人困惑。
当我使用 Azure AD Graph API 查询用户对象时,会返回自定义属性(例如“CreatedTime”)。https://graph.windows.net/{tenant}/users/{objectId}
返回:
{
"odata.metadata": "https://graph.windows.net/{tenant}/$metadata#directoryObjects/Microsoft.DirectoryServices.User/@Element",
"odata.type": "Microsoft.DirectoryServices.User",
"objectType": "User",
...
"extension_917ef9adff534c858b0a683b6e6ec0f3_CreatedTime": 1518602039
}
当我使用 Microsoft Graph API 查询同一个对象时,不会返回自定义属性。
https://graph.microsoft.com/v1.0/users/{id}/extensions
返回:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('{id}')/extensions",
"value": []
}
除非您得到更好的答案,否则我建议您使用 Azure AD Graph API,并且可以选择 the Azure AD Graph Client , 获取和设置 Azure AD B2C 用户的扩展属性。
获取和设置用户扩展属性的示例可以在 Announcing Azure AD Graph API Client Library 2.0 中找到。
关于c# - 如何在 ASP.NET MVC 中获取/设置自定义 Azure Active Directory B2C 用户属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48769708/