为什么graphClient.Me.Request()。GetAsync()为某些非空的AAD配置文件字段返回空值?

问题描述 投票:1回答:1

我正在使用Graph API从UWP应用程序访问用户信息。我正在使用Azure App服务与客户端UWP应用程序和Azure后端。

我的Azure Active Directory只有我和测试用户。我的应用程序中的以下行确实从AAD返回了一些我的信息:

Microsoft.Graph.GraphServiceClient graphClient =
        new Microsoft.Graph.GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
       requestMessage.Headers.Authorization =
           new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", result2.AccessToken);
       return Task.FromResult(0);
}));

Microsoft.Graph.User user = await graphClient.Me.Request().GetAsync();

但是,当我在调用后检查“user”变量的内容时,除DisplayName,GivenName,ID,JobTitle,AdditionalItems和UserPrincipleName之外,所有字段都列为null。非null的值是正确的。但是,我还填写了所有街道地址字段,并为我在AAD上的个人资料提供了个人资料图片。但是,这些也回来了。有谁能告诉我是什么原因造成的? (我检查了随请求发送的访问令牌,它似乎确实包含了所需的权限。为了确保,我在AAD中注册我的应用程序时请求了所有委托所需的Windows Azure AD和Microsoft Graph权限。)

谢谢。

azure-active-directory azure-mobile-services microsoft-graph
1个回答
3
投票

Microsoft Graph在每个响应中返回默认的核心属性集。您可以使用$select查询参数来获取其他属性。

例如,GET https://graph.microsoft.com/v1.0/me/不会为用户返回streetAddress字段,但GET https://graph.microsoft.com/v1.0/me/?$select=streetaddress会返回它。您可以通过使用$select=id,jobTitle,streetAddress等逗号分隔字段来获取多个属性。

使用.NET SDK,我相信语法是Request().Select("assignedLicenses").GetAsync()documentation for this is on GitHub

© www.soinside.com 2019 - 2024. All rights reserved.