Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

c# - Querying AzureAD Graph extension attributes with Microsoft Graph

I am in the process of migrating away from Azure AD Graph API to Microsoft Graph since it is now deprecated. Previously it was possible to access extended properties against a user using Microsoft.Azure.ActiveDirectory.GraphClient .GetExtendedProperties(); call e.g:

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

I need to replicate this with equivalent calls in Microsoft Graph.

I have looked at the schemaExtensions endpoint, e.g:

GET all extensions:

/v1.0/schemaExtensions

But this doesn't appear to return the same extensions data that the AD Graph Client did.

GET user with ext:

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

Where extension_[application id]_myExtension is an example extension in the format:

extension_appid_extensionname

And this doesn't return the custom extension data for the user (other properties work fine however).

How can we migrate extended properties from AD Graph Client to Microsoft Graph?

question from:https://stackoverflow.com/questions/66050611/querying-azuread-graph-extension-attributes-with-microsoft-graph

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

SchemaExtensions is different from extensionProperty. What you mentioned should be extensionProperty in Microsoft Graph.

You can use List extensionProperties to get all extensions.

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

Please make sure that the application id should remove all -. The extension property format is extension_[application id without "-"]_myExtension.

For example:

GET https://graph.microsoft.com/v1.0/me?$select=id,extension_6d****fbf1fe4bc38a5a145520****89_policy,displayName

Response:

{
    "@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"
}

enter image description here

The C# code sample:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...