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の複製です。回避策はありますが、この方法が機能しない理由は説明されていません。