小编Gio*_*rdo的帖子

使用Microsoft Graph通过userPrincipalName获取来宾用户

我正在与Microsoft Graph一起玩,以直接使用REST API(没有SDK)从我的应用程序访问Azure Active Directory。

根据文档,我应该能够从用户iduserPrincipalName使用中检索用户/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)

我是否缺少某些东西或做错了什么?

microsoft-graph

5
推荐指数
2
解决办法
2096
查看次数

标签 统计

microsoft-graph ×1