Sean's answer is a bit outdated. Now you can configure Azure AD to include groups or roles within the JWT token, so it will be included in ClaimsPrincipal.Current.Claims , so the standard attribute [Authorize(Roles = "yourRoleName")] will work.
There is a message entry. Which basically says that you have two options:
Claims for using groups - you need to change the value of groupMembershipClaims in the application manifest and then in the application that you can check for ClaimsPrincipal.Current.FindFirst("groups").Value to find out which group the user is in (you get only the group identifier ) You can write your own Authorize attribute that uses this. more details
Define the roles for your application, and then use regular code for testing if the user is in a role:
[PrincipalPermission(SecurityAction.Demand, Role = "yourRoleName")]
[Authorize(Roles = "yourRoleName")]
if (ClaimsPrincipal.Current.IsInRole("yourRoleName")) { //do something }
You need to change the roles in your application manifest. More details here and here . The values ββto be set in the manifest are described here.
What is really strange is that you cannot assign more than one role to a group from the Azure web page. For this you need to use azure graph api .
If you donβt see the Users and Groups tab in the Azure portal, you will probably need Azure AD Basic or Premium edition. If you are working on a free azure subscription, you can use the free trial version of Azure AD Premium for testing.
source share