1

我正在使用 Microsoft.Azure.ActiveDirectory.GraphClient 版本 2.1.1.0 来获取我的用户所属的组。方法调用是这样的:

ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(
                                        new Uri(GraphUrl),
                                        async () => await GetAppTokenAsync());

IEnumerable<string> groups = GetGroupsAsync(activeDirectoryClient, "currentUserObjectId").Result;

private static async Task<IEnumerable<string>> GetGroupsAsync(ActiveDirectoryClient activeDirectoryClient, string currentUserObjectId )
{
    return await activeDirectoryClient.Users.GetByObjectId(currentUserObjectId).GetMemberGroupsAsync(true);

}

private static async Task<string> GetAppTokenAsync()
{
            var authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(ServiceRoot);
            var token = await authContext.AcquireTokenAsync(GraphUrl,new ClientCredential("clientId", "clientSecret"));
            return token.AccessToken;
}

但是,即使在 Fiddler 中我看到请求已成功并且包含正确的组,该方法也会挂起。

我的问题是Azure ActiveDirectory Graph API GraphClient not return AD Groups的重复。存在一种解决方法,但不能解释为什么该方法不起作用。

4

2 回答 2

0

在使用 Result 属性时,我在 Graph Api 库中遇到了类似的问题,请尝试将您的调用更改为:-

IEnumerable<string> groups = await GetGroupsAsync(activeDirectoryClient, "currentUserObjectId");
于 2016-02-17T14:13:48.330 回答
0

如果您的 ActiveDirectoryClient 实例化和对 AuthenticationContext 的调用确实您的 ServiceRoot 值相同,那么这可能是您的问题的根源。

ActiveDirectoryClient 应使用https://graph.windows.net/进行实例化

AuthenticationContext 应该使用 https://login.microsoftonline.com/调用

尽管这不会在方法挂起或成功请求中表现出来,但这是我必须对您的代码进行的唯一更改才能使其为我工作,否则它将返回 Not Found 错误。

于 2016-02-12T23:36:31.347 回答