Returning Azure Active Directory groups as claims.

Returning a list of Azure Active Directory groups that a user is part of.

To enable this you need to modify the application manifest.

  1. Goto the Azure portal
  2. Click on Azure Active Directory
  3. Click on App registrations
  4. Choose the application that you are working with
  5. Click on Manifest

The application manifest has all the configuration details for your application.

By default the property groupMembershipClaims is null, by changing it to “SecurityGroup” you will have the list of groups returned as a claim.

"groupMembershipClaims": "SecurityGroup",

Accessing the groups

The groups returned will only be the guids of the group ids, so you will either need to look up the object ids in code, or store the object ids, depending how you

internal static bool IsAuthorised(ClaimsPrincipal currentPrincipal)
{
    var authorisedGroupIDs = "GUID1,GUID2";

    var principalsGroupMembershipIds = currentPrincipal.Claims.Where(c => c.Type == "groups").Select(c => c.Value).ToList();

    var isAuthorised = principalsGroupMembershipIds
        .Any(x => authorisedGroupIDs.Contains(x));

    return isAuthorised;
}