問題描述
我在 Azure Active Directory B2C 租戶中添加了一個自定義 Organization
字段作為用戶屬性,如下所示:
I have added a custom Organization
field as a User Attribute in my Azure Active Directory B2C tenant, like so:
我正在使用 Microsoft Graph .NET 客戶端庫來管理 Azure 中的用戶Active Directory B2C 并希望使用類似于以下代碼的內容來設置用戶的自定義 Organization
字段和用戶的內置 Email Addresses
字段.
I am using the Microsoft Graph .NET Client Library to manage users in Azure Active Directory B2C and would like to use something similar to the following code to set the user's custom Organization
field and the user's built-in Email Addresses
field.
await graphClient.Users[user.Id].Request().UpdateAsync(new User()
{
Email Addresses = new StringCollection("myemail@mydomain.com")
Organization = "Microsoft"
});
兩個問題:
- 如何設置內置字段,例如
電子郵件地址
? - 如何設置自定義字段,例如
Organization
?
本文檔顯示 如何創建自定義屬性,但不告訴如何使用圖形客戶端訪問或使用該屬性.
This documentation shows how to create a custom attribute but does not tell how to access or use that attribute using the Graph Client.
本文檔展示了如何創建自定義屬性并編輯依賴方 (RP) 文件.
有沒有更簡單的方法?然后獲取/設置這些自定義用戶屬性的 graphClient
代碼是什么?
Is there an easier way? And what is the graphClient
code to then get/set these custom user attributes?
推薦答案
Microsoft Graph API 以及 Microsoft Graph 客戶端是否支持向 Azure AD B2C 租戶注冊的擴展屬性有點令人困惑.
It is a bit confusing about whether the Microsoft Graph API, and hence the Microsoft Graph Client, supports the extension properties that are registered with an Azure AD B2C tenant.
當我使用 Azure AD Graph API 查詢用戶對象時,會返回自定義屬性(例如CreatedTime").
When I query a user object using the Azure AD Graph API, then the custom attributes (e.g. "CreatedTime") are returned.
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 查詢同一個對象時,不會返回自定義屬性.
When I query the same object using the Microsoft Graph API, then the custom attributes aren't returned.
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,也可以選擇 Azure AD Graph 客戶端,用于獲取和設置 Azure AD B2C 用戶的擴展屬性.
Unless you receive a better answer, then I suggest you use the Azure AD Graph API, and optionally the Azure AD Graph Client, to get and set the extension properties for the Azure AD B2C users.
獲取和設置用戶擴展屬性的示例可以在 宣布 Azure AD Graph API 客戶端庫 2.0
Examples of getting and setting the extension properties for users can be found at Announcing Azure AD Graph API Client Library 2.0
這篇關于如何在 ASP.NET MVC 中獲取/設置自定義 Azure Active Directory B2C 用戶屬性?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!