使用 Microsoft Graph 查询 AzureAD Graph 扩展属性

DGi*_*bbs 5 c# azure azure-active-directory azure-ad-graph-api microsoft-graph-api

我正在从 Azure AD Graph API 迁移到 Microsoft Graph,因为它现已弃用。以前可以使用Microsoft.Azure.ActiveDirectory.GraphClient .GetExtendedProperties();调用来访问用户的扩展属性,例如:

var client = new ActiveDirectoryClient(serviceRoot, async () => await GetToken());
var user = await client.Users["user id..."].ExecuteAsync();
var properties = user.GetExtendedProperties();
Run Code Online (Sandbox Code Playgroud)

我需要使用 中的等效调用来复制此内容Microsoft Graph

我查看了schemaExtensions端点,例如:

获取所有扩展名:

/v1.0/schemaExtensions

但这似乎不会返回与 AD Graph 客户端相同的扩展数据。

使用 ext 获取用户:

v1.0/users/[user id]?$expand=extensions&$select=id,extension_[application id]_myExtension,onPremisesExtensionAttributes,displayName,jobTitle,identities

哪里extension_[application id]_myExtension有格式示例扩展:

extension_appid_extensionname

并且这不会返回用户的自定义扩展数据(但是其他属性工作正常)。

我们如何将扩展属性从 AD Graph 客户端迁移到 Microsoft Graph?

All*_* Wu 3

SchemaExtensions与extensionProperty不同。你提到的应该是Microsoft Graph中的extensionProperty

您可以使用List extensionProperties来获取所有扩展。

你的要求v1.0/users/[user id]?$expand=extensions&$select=id,extension_[application id]_myExtension,onPremisesExtensionAttributes,displayName,jobTitle,identities应该是正确的。

请确保application id应删除所有-. 扩展属性格式为extension_[application id without "-"]_myExtension.

例如:

GET https://graph.microsoft.com/v1.0/me?$select=id,extension_6d****fbf1fe4bc38a5a145520****89_policy,displayName
Run Code Online (Sandbox Code Playgroud)

回复:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,extension_6d****fbf1fe4bc38a5a145520****89_policy,displayName)/$entity",
    "id": "98****c9-f062-48e2-8ced-22cb68****ce",
    "displayName": "Allen Wu",
    "extension_6d****fbf1fe4bc38a5a145520****89_policy": "readwrite"
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

C# 代码示例:

var user = await graphClient.Users["98****c9-f062-48e2-8ced-22cb6****ce"]
    .Request()
    .Select("id,extension_6d****fbf1fe4bc38a5a145520****89_policy,displayName")
    .GetAsync();
Run Code Online (Sandbox Code Playgroud)