我正在与Microsoft Graph一起玩,以直接使用REST API(没有SDK)从我的应用程序访问Azure Active Directory。
根据文档,我应该能够从用户id或userPrincipalName使用中检索用户/users/{id | userPrincipalName}。
这确实有效,但不适用于Guest用户。对于Guest用户userPrincipalName来说就像是name_originaldomain#EXT#@mydomain.onmicrosoft.com,并试图使用户获得结果404 Not Found。
这是我当前正在使用的代码:
graphClient = new HttpClient();
graphClient.BaseAddress = new Uri("https://graph.microsoft.com/v1.0/");
graphClient.DefaultRequestHeaders.Add("Authorization", $"{token.TokenType} {token.AccessToken}");
HttpRequestMessage request = new HttpRequestMessage(
HttpMethod.Get,
$"users/{Uri.EscapeUriString(username)}"
);
HttpResponseMessage response = await graphClient.SendAsync(request);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsAsync<UserResult>();
}
// I am here with a 404
Run Code Online (Sandbox Code Playgroud)
我是否缺少某些东西或做错了什么?