use*_*494 4 javascript azure-active-directory microsoft-graph
我们有一个应用程序,它使用本地AD来获取用户信息.有些客户希望迁移到云并使用Azure AD.我们扩展了应用程序以通过owin签署用户,现在我们通过Microsoft Graph获取用户.
但是,从Microsoft Graph我们没有获得完整的用户配置文件.我们想要获取用户的所有属性,而不仅仅是基本属性.
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);
Run Code Online (Sandbox Code Playgroud)
这只给了我一些信息,例如我从这里得不到'部门'.是否可以在azure中配置应该返回的内容,如果是,那么在哪里?或者我还需要其他东西/users/吗?
不同的客户可能具有需要获取的不同特殊属性.因此,最好的解决方案是让端点调用并获取所有内容,包括azure广告中不标准的特殊属性.之后,我可以解析它在我身边.这可能吗?
应用程序拥有读取基本和完整配置文件的权限.我还需要更多东西吗?
小智 7
User user = await graphServiceClient
.Users[emailId]
.Request()
.Select(aadUser => new
{
aadUser.Id,
aadUser.UserPrincipalName,
aadUser.DisplayName,
aadUser.GivenName,
aadUser.Surname,
aadUser.City,
aadUser.MailNickname,
aadUser.UserType
})
.GetAsync()
.ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)
这是Graph API的正常行为,请参阅此处的文档和此摘录:
缺省情况下,只有有限的一组属性的返回(
businessPhones,displayName,givenName,id,jobTitle,mobilePhone,officeLocation,preferredLanguage,surname,userPrincipalName).要返回备用属性集,必须使用OData
$select查询参数指定所需的用户属性集.例如,要返回displayName,givenName和postalCode,您可以使用以下内容添加到查询中$select=displayName,givenName,postalCode
您必须在select中指定所有字段,因为$select=*只会在Graph API实现中输出关键字段.
所以你将无法得到你所要求的(可变自定义字段).
有关用户字段的更多信息,请访问此处