【发布时间】:2021-12-12 16:29:31
【问题描述】:
在我的 ASP.NET Core Web Api 中,我尝试调用 Graph API 来检索组织中其他用户的数据。我正在使用代表流程。引导令牌是从 SPA 客户端代码传入的。
在启动代码中,我有:
builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddMicrosoftGraph("https://graph.microsoft.com/beta", "user.read user.readbasic.all profile")
.AddInMemoryTokenCaches();
在Controller的Action中,我有:
_graphServiceClient.Users.Request()
.Filter($"mail eq 'someuser@myorg.com'")
.Select((user) => new {
DisplayName = user.DisplayName,
City = user.City,
Country = user.Country,
BusinessPhones = user.BusinessPhones
})
.Request()
.GetAsync();
但是,在运行时,我只能得到 DisplayName 值。我不明白 City、Country 或 BusinessPhones 的值。他们是null。
当我在 Graph Explorer 中尝试相同的查询时,我看到了所有这些查询的值。
我错过了什么?
【问题讨论】:
-
您有什么理由使用 beta API 而不是 1.0 API?
-
你在api权限中启用
profile了吗?
标签: asp.net-web-api microsoft-graph-api asp.net-identity claims-based-identity microsoft-graph-sdks