从 Microsoft graph 获取所有用户属性 [英] Get all user properties from Microsoft graph

查看:19
本文介绍了从 Microsoft graph 获取所有用户属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用本地 AD 获取用户信息的应用程序.一些客户希望迁移到云并使用 Azure AD.我们将应用扩展为通过 owin 登录用户,现在我们通过 Microsoft Graph 获取用户.

We have an application which has used a local AD to fetch user info. Some customers want to move to the cloud and are using Azure AD. We extended the app to sign users in via owin and now we're fetching users via Microsoft Graph.

但是,我们无法从 Microsoft Graph 获得完整的用户配置文件.我们希望获取用户的所有属性,而不仅仅是基本属性.

However from Microsoft Graph we do not get full user profiles. We want to fetch all properties on users, not just the basic ones.

var client = new RestClient(string.Format("https://graph.microsoft.com/v1.0/users/{0}", userEmail));
request = new RestRequest();
request.Method = Method.GET;
request.AddHeader("Authorization", _token.Token);
var reponse = client.Execute(request);

这只是给了我一些信息,例如我没有从中得到部门".是否可以在 azure 中配置应该在此处返回的内容,如果可以,那么在哪里?还是我需要 /users/ 以外的东西?

This only gives me some information though, for example I don't get 'Department' from this. Is it possible to configure in azure what should be returned here, if so then where? Or do I need something other than /users/?

不同的客户可能有不同的特殊属性需要获取.因此,最好的解决方案是有一个端点来调用并获取所有内容,包括 azure ad 中不标准的特殊属性.之后,我可以在我这边解析它.这可能吗?

Different customers might have different special properties that need to be fetched. So the best solution would be to have an endpoint to call and get everything, including special properties not standard in azure ad. After that I can parse it on my side. Is this possible?

该应用有权读取基本配置文件和完整配置文件.我还需要什么吗?

The app has permission to read both basic and full profiles. Do I need something more?

推荐答案

这是 Graph API 的正常行为,请参阅文档 这里和这段摘录:

That's the normal behaviour of Graph API, see documentation here and this extract:

默认情况下,只返回一组有限的属性(businessPhonesdisplayNamegivenNameidjobTitlemail,mobilePhoneofficeLocationpreferredLanguagesurnameuserPrincipalName).

By default, only a limited set of properties are returned ( businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, userPrincipalName).

要返回替代属性集,您必须指定所需的使用 OData $select 查询参数的一组用户属性.为了例如,要返回 displayName、givenName 和 postalCode,您可以使用将以下内容添加到您的查询中$select=displayName,givenName,postalCode

To return an alternative property set, you must specify the desired set of user properties using the OData $select query parameter. For example, to return displayName, givenName, and postalCode, you would use the add the following to your query $select=displayName,givenName,postalCode

您必须在选择中指定所有字段,因为 $select=* 只会输出 Graph API 实现中的关键字段.

You have to specify all fields in the select, as $select=* will only output the key fields in Graph API implementation.

所以你将无法得到你所要求的(可变的自定义字段).

So you will not be able to get what you ask (variable custom fields).

可以找到有关用户字段的更多信息 这里

More info on the fields of User can be found here

这篇关于从 Microsoft graph 获取所有用户属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆