I am trying to get a group of users from azure ad graph. When I make the call it is returning the AccountEnabled property as null. After doing some research I noticed that it is most likely related to api permissions assingned to the app registration I am using for the token. I added the User.Read.All permission to it which should add the correct permissions to read all properties of a user but I am still getting null for AccountEnabled. I am building the token using the app registration credentials. Does anyone know what I am doing wrong?
public async Task<List<GroupMember>> GetAllGroupMembers(string userAccessToken, string destination)
{
var centreDetails = await _centreService.GetCentreDetailsBy(userAccessToken, destination);
var graphClient = await GetGraphClient();
var groupMembers = new List<GroupMember>();
var transitiveMembers = await graphClient.Groups[centreDetails.distributionGroup.azureId].TransitiveMembers.Request().GetAsync();
while (transitiveMembers != null && transitiveMembers.Count > 0)
{
var members = transitiveMembers.CurrentPage.Where(member => member is User);
foreach (User member in members)
{
groupMembers.Add(new GroupMember
{
Id = member.Id,
Name = member.DisplayName,
AccountEnabled = member.AccountEnabled
});
}
if (transitiveMembers.NextPageRequest != null)
{
transitiveMembers = await transitiveMembers.NextPageRequest.GetAsync();
}
else
{
break;
}
}
return groupMembers;
}
By default graph doesn't return this property and you will get back a standard set. If you need something specific you have to explicitly declare all desired properties. If you send a call by using the graph explorer you'll get back this as a tip in the response.
Instead you have to explicitly select which properties you need and in v4 SDK you define the desired properties by calling .Request().Select("id,displayName,accountEnabled").GetAsync();