我正在使用 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的重复。存在一种解决方法,但不能解释为什么该方法不起作用。