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

问题描述

我们有一个应用程序,它使用本地AD来获取用户信息。有些客户希望迁移到云并使用Azure AD。我们扩展了应用程序以通过owin签署用户,现在我们通过Microsoft Graph获取用户。

We have an application wich 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 dont 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广告中不标准的特殊属性。之后,我可以解析它在我身边。这可能吗?

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?

app har读取基本和完整配置文件的权限。我需要更多的东西吗?

The app har 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:

要返回备用属性集,必须使用OData <$ c指定所需的
用户属性集$ c> $ 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中的所有字段,如 $ 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

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

08-15 22:03