| page_type | description | languages | products | urlFragment | extensions | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
This sample demonstrates a cross-platform application suite involving an Angular single-page application (TodoListSPA) calling an ASP.NET Core web API (TodoListAPI) secured with the Microsoft identity platform. In doing so, it implements Role-based Access Control (RBAC) by using Azure AD Security Groups. |
|
|
spa-msal-angular-security-groups |
|
Angular single-page application calling a protected ASP.NET Core web API and using Security Groups to implement Role-Based Access Control
- Overview
- Scenario
- Prerequisites
- Setup the sample
- Explore the sample
- Troubleshooting
- About the code
- Next Steps
- Contributing
- Learn More
This sample demonstrates a cross-platform application suite involving an Angular single-page application (TodoListSPA) calling an ASP.NET Core web API (TodoListAPI) secured with the Microsoft identity platform. In doing so, it implements Role-based Access Control (RBAC) by using Azure AD Security Groups.
Role based access control in Azure AD can be done with Delegated and App permissions and App Roles as well. We will cover RBAC using App Roles in the previous tutorial. Delegated and App permissions, Security Groups and App Roles in Azure AD are by no means mutually exclusive - they can be used in tandem to provide even finer grained access control.
In the sample, a dashboard component allows signed-in users to see the tasks assigned to them or other users based on their memberships to one of the two security groups, GroupAdmin and GroupMember.
ℹ️ See the community call: Deep dive on using MSAL.js to integrate Angular single-page applications with Azure Active Directory
ℹ️ See the community call: Implement authorization in your applications with App roles and Security Groups with the Microsoft identity platform
- The TodoListSPA uses MSAL Angular to authenticate a user with the Microsoft identity platform.
- The app then obtains an access token from Azure Active Directory (Azure AD) on behalf of the authenticated user for the TodoListAPI.
- TodoListAPI uses Microsoft.Identity.Web to protect its endpoint and accept only authorized calls.
| File/folder | Description |
|---|---|
SPA/src/app/auth-config.ts |
Authentication parameters for SPA project reside here. |
SPA/src/app/app.module.ts |
MSAL Angular is initialized here. |
SPA/src/app/group.guard.ts |
This service protects other components that require user to be in a group. |
SPA/src/app/graph.service.ts |
This service queries Microsoft Graph in case of groups overage. |
API/appsettings.json |
Authentication parameters for API project reside here. |
API/Startup.cs |
Microsoft.Identity.Web is initialized here. |
API/Utils/GraphHelper.cs |
Queries Microsoft Graph with Graph SDK in case groups overage occurs. |
- Either Visual Studio or Visual Studio Code and .NET Core SDK
- An Azure AD tenant. For more information, see: How to get an Azure AD tenant
- A user account in your Azure AD tenant. This sample will not work with a personal Microsoft account. If you're signed in to the Azure portal with a personal Microsoft account and have not created a user account in your directory before, you will need to create one before proceeding.
From your shell or command line:
git clone https://github.com/Azure-Samples/ms-identity-javascript-angular-tutorial.gitor download and extract the repository .zip file.
⚠️ To avoid path length limitations on Windows, we recommend cloning into a directory near the root of your drive.
cd ms-identity-javascript-angular-tutorial
cd 5-AccessControl/2-call-api-groups/API
dotnet restore dotnet dev-certs https --clean
dotnet dev-certs https --trustFor more information and potential issues, see: HTTPS in .NET Core.
cd ../
cd SPA
npm installℹ️ While there are multiple projects in this sample, we'd register just one app with Azure AD and use the registered app's client id in both apps. This reuse of app ids (client ids) is used when the apps themselves are just components of one larger app topology.
There is one project in this sample. To register it, you can:
-
follow the steps below for manually register your apps
-
or use PowerShell scripts that:
- automatically creates the Azure AD applications and related objects (passwords, permissions, dependencies) for you.
- modify the projects' configuration files.
Expand this section if you want to use this automation:
⚠️ If you have never used Microsoft Graph PowerShell before, we recommend you go through the App Creation Scripts Guide once to ensure that your environment is prepared correctly for this step.-
On Windows, run PowerShell as Administrator and navigate to the root of the cloned directory
-
In PowerShell run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
-
Run the script to create your Azure AD application and configure the code of the sample application accordingly.
-
For interactive process -in PowerShell, run:
cd .\AppCreationScripts\ .\Configure.ps1 -TenantId "[Optional] - your tenant id" -AzureEnvironmentName "[Optional] - Azure environment, defaults to 'Global'"
Other ways of running the scripts are described in App Creation Scripts guide. The scripts also provide a guide to automated application registration, configuration and removal which can help in your CI/CD scenarios.
To manually register the apps, as a first step you'll need to:
- Sign in to the Azure portal.
- If your account is present in more than one Azure AD tenant, select your profile at the top right corner in the menu on top of the page, and then switch directory to change your portal session to the desired Azure AD tenant.
:information_source: Below, we are using a single app registration for both SPA and web API projects. We will configure the web API to accept only the calls coming from this client SPA.
- Navigate to the Azure portal and select the Azure Active Directory service.
- Select the App Registrations blade on the left, then select New registration.
- In the Register an application page that appears, enter your application's registration information:
- In the Name section, enter a meaningful application name that will be displayed to users of the app, for example
msal-angular-app. - Under Supported account types, select Accounts in this organizational directory only
- Select Register to create the application.
- In the Name section, enter a meaningful application name that will be displayed to users of the app, for example
- In the Overview blade, find and note the Application (client) ID. You use this value in your app's configuration file(s) later in your code.
- In the app's registration screen, select the Authentication blade to the left.
- If you don't have a platform added, select Add a platform and select the Single-page application option.
- In the Redirect URI section enter the following redirect URIs:
http://localhost:4200/http://localhost:4200/auth
- Click Save to save your changes.
- In the Redirect URI section enter the following redirect URIs:
- In the app's registration screen, select the Certificates & secrets blade in the left to open the page where you can generate secrets and upload certificates.
- In the Client secrets section, select New client secret:
- Type a key description (for instance
app secret). - Select one of the available key durations (6 months, 12 months or Custom) as per your security posture.
- The generated key value will be displayed when you select the Add button. Copy and save the generated value for use in later steps.
- You'll need this key later in your code's configuration files. This key value will not be displayed again, and is not retrievable by any other means, so make sure to note it from the Azure portal before navigating to any other screen or blade.
💡 For enhanced security, instead of using client secrets, consider using certificates and Azure KeyVault.
- Type a key description (for instance
- In the app's registration screen, select the Expose an API blade to the left to open the page where you can publish the permission as an API for which client applications can obtain access tokens for. The first thing that we need to do is to declare the unique resource URI that the clients will be using to obtain access tokens for this API. To declare an resource URI(Application ID URI), follow the following steps:
- Select Set next to the Application ID URI to generate a URI that is unique for this app.
- For this sample, accept the proposed Application ID URI (
api://{clientId}) by selecting Save. Read more about Application ID URI at Validation differences by supported account types (signInAudience).
- All APIs must publish a minimum of one scope, also called Delegated Permission, for the client apps to obtain an access token for a user successfully. To publish a scope, follow these steps:
- Select Add a scope button open the Add a scope screen and Enter the values as indicated below:
- For Scope name, use
access_via_group_assignments. - Select Admins and users options for Who can consent?.
- For Admin consent display name type in Access 'msal-angular-app' as the signed-in user assigned to group memberships.
- For Admin consent description type in Allow the app to access the 'msal-angular-app' as a signed-in user assigned to one or more security groups.
- For User consent display name type in Access 'msal-angular-app' on your behalf after security group assignment.
- For User consent description type in Allow the app to access the 'msal-angular-app' on your behalf after assignment to one or more security groups.
- Keep State as Enabled.
- Select the Add scope button on the bottom to save this scope.
- For Scope name, use
- Select the Manifest blade on the left.
- Set
accessTokenAcceptedVersionproperty to 2. - Select on Save.
- Set
ℹ️ Follow the principle of least privilege when publishing permissions for a web API.
- Since this app signs-in users, we will now proceed to select delegated permissions, which is is required by apps signing-in users.
- In the app's registration screen, select the API permissions blade in the left to open the page where we add access to the APIs that your application needs:
- Select the Add a permission button and then:
- Ensure that the My APIs tab is selected.
- In the list of APIs, select the API
msal-angular-app. - In the Delegated permissions section, select access_via_group_assignments in the list. Use the search box if necessary.
- Select the Add permissions button at the bottom.
- Select the Add a permission button and then:
- Ensure that the Microsoft APIs tab is selected.
- In the Commonly used Microsoft APIs section, select Microsoft Graph
- In the Delegated permissions section, select User.Read, GroupMember.Read.All in the list. Use the search box if necessary.
- Select the Add permissions button at the bottom.
- Select the Add a permission button and then:
⚠️ To handle the groups overage scenario, please grant admin consent to the Microsoft Graph GroupMember.Read.All permission. See the section on how to create the overage scenario for testing below for more.
- Still on the same app registration, select the Token configuration blade to the left.
- Select Add optional claim:
- Select optional claim type, then choose ID.
- Select the optional claim acct.
Provides user's account status in tenant. If the user is a member of the tenant, the value is 0. If they're a guest, the value is 1.
- Select optional claim type, then choose Access.
- Select the optional claim idtyp.
Indicates token type. This claim is the most accurate way for an API to determine if a token is an app token or an app+user token. This is not issued in tokens issued to users.
- Select Add to save your changes.
Open the project in your IDE (like Visual Studio or Visual Studio Code) to configure the code.
In the steps below, "ClientID" is the same as "Application ID" or "AppId".
-
Open the
API\TodoListAPI\appsettings.jsonfile. -
Find the key
Enter the ID of your Azure AD tenant copied from the Azure portaland replace the existing value with your Azure AD tenant/directory ID. -
Find the key
Enter the application ID (clientId) of the 'TodoListAPI' application copied from the Azure portaland replace the existing value with the application ID (clientId) ofmsal-angular-appapp copied from the Azure portal. -
Find the key
Enter the Client Secret of the 'TodoListAPI' application copied from the Azure portaland replace the existing value with the key you saved during the creation ofmsal-angular-appcopied from the Azure portal. -
Open the
SPA\src\app\auth-config.tsfile. -
Find the key
Enter_the_Application_Id_Hereand replace the existing value with the application ID (clientId) ofmsal-angular-appapp copied from the Azure portal. -
Find the key
Enter_the_Tenant_Info_Hereand replace the existing value with your Azure AD tenant/directory ID. -
Find the key
Enter_the_Web_Api_Application_Id_Hereand replace the existing value with the application ID (clientId) ofmsal-angular-appapp copied from the Azure portal.
⚠️ You may already have security groups with the names defined below in your tenant and/or you may not have permissions to create new security groups. In that case, skip the steps below and update the configuration files in your project(s) with the desired names/IDs of existing groups in your tenant.
- Navigate to the Azure portal and select the Azure Active Directory service.
- Select Groups blade on the left.
- In the Groups blade, select New Group.
- For Group Type, select Security
- For Group Name, enter GroupAdmin
- For Group Description, enter Admin Security Group
- Add Group Owners and Group Members as you see fit.
- Select Create.
- In the Groups blade, select New Group.
- For Group Type, select Security
- For Group Name, enter GroupMember
- For Group Description, enter User Security Group
- Add Group Owners and Group Members as you see fit.
- Select Create.
- Assign the user accounts that you plan to work with to these security groups.
For more information, visit: Create a basic group and add members using Azure AD
You have two different options available to you on how you can further configure your application to receive the groups claim.
- Receive all the groups that the signed-in user is assigned to in an Azure AD tenant, included nested groups.
- Receive the groups claim values from a filtered set of groups that your application is programmed to work with (Not available in the Azure AD Free edition).
To get the on-premise group's
samAccountNameorOn Premises Group Security Identifierinstead of Group ID, please refer to the document Configure group claims for applications with Azure Active Directory.
Configure your application to receive all the groups the signed-in user is assigned to, including nested groups
- In the app's registration screen, select the Token Configuration blade in the left to open the page where you can configure the claims provided tokens issued to your application.
- Select the Add groups claim button on top to open the Edit Groups Claim screen.
- Select
Security groupsor theAll groups (includes distribution lists but not groups assigned to the application)option. Choosing both negates the effect ofSecurity Groupsoption. - Under the ID section, select
Group ID. This will result in Azure AD sending the object id of the groups the user is assigned to in the groups claim of the ID Token that your app receives after signing-in a user.
Configure your application to receive the groups claim values from a filtered set of groups a user may be assigned to
- This option is useful when your application is interested in a selected set of groups that a signing-in user may be assigned to and not every security group this user is assigned to in the tenant. This option also saves your application from running into the overage issue.
- This feature is not available in the Azure AD Free edition.
- Nested group assignments are not available when this option is utilized.
- In the app's registration screen, select the Token Configuration blade in the left to open the page where you can configure the claims provided tokens issued to your application.
- Select the Add groups claim button on top to open the Edit Groups Claim screen.
- Select
Groups assigned to the application.- Choosing additional options like
Security GroupsorAll groups (includes distribution lists but not groups assigned to the application)will negate the benefits your app derives from choosing to use this option.
- Choosing additional options like
- Under the ID section, select
Group ID. This will result in Azure AD sending the object id of the groups the user is assigned to in thegroupsclaim of the ID Token that your app receives after signing-in a user. - If you wish to have 'groups' claims available to Access Tokens issued to your Web API, then you can also choose the
Group IDoption under the Access section. This will result in Azure AD sending the Object ID of the groups the user is assigned to in thegroupsclaim of the Access Token issued to the client applications of your API. - In the app's registration screen, select on the Overview blade in the left to open the Application overview screen. Select the hyperlink with the name of your application in Managed application in local directory (note this field title can be truncated for instance
Managed application in ...). When you select this link you will navigate to the Enterprise Application Overview page associated with the service principal for your application in the tenant where you created it. You can navigate back to the app registration page by using the back button of your browser. - Select the Users and groups blade in the left to open the page where you can assign users and groups to your application.
- Select the Add user button on the top row.
- Select User and Groups from the resultant screen.
- Choose the groups that you want to assign to this application.
- Click Select in the bottom to finish selecting the groups.
- Select Assign to finish the group assignment process.
- Your application will now receive these selected groups in the
groupsclaim when a user signing in to your app is a member of one or more these assigned groups.
- Select the Properties blade in the left to open the page that lists the basic properties of your application.Set the User assignment required? flag to Yes.
💡 Important security tip
When you set User assignment required? to Yes, Azure AD will check that only users assigned to your application in the Users and groups blade are able to sign-in to your app.To enable this, follow the instructions here. You can assign users directly or by assigning security groups they belong to.
⚠️ During Token Configuration, if you have chosen any other option except groupID (e.g. like DNSDomain\sAMAccountName) you should enter the group name (for examplecontoso.com\Test Group) instead of the object ID below:
-
Open the
SPA\src\app\auth-config.tsfile. -
Find the key
Enter the objectID for GroupAdmin group copied from Azure Portaland replace the existing value with the object ID of the GroupAdmin group copied from the Azure portal. -
Find the key
Enter the objectID for GroupMember group copied from Azure Portaland replace the existing value with the object ID of the GroupMember group copied from the Azure portal. -
Open the
API\TodoListAPI\appsettings.jsonfile. -
Find the key
Enter the objectID for 'GroupAdmin' group copied from Azure Portaland replace the existing value with the object ID of the GroupAdmin group copied from the Azure portal. -
Find the key
Enter the objectID for 'GroupMember' group copied from Azure Portaland replace the existing value with the object ID of the GroupMember group copied from the Azure portal.
Using a command line interface such as VS Code integrated terminal, locate the application directory. Then:
cd SPA
npm startIn a separate console window, execute the following commands:
cd API\TodoListAPI
dotnet run- Open your browser and navigate to
http://localhost:4200. - Sign-in using the button on top-right:
- Click on the Get My Tasks button to access your (the signed-in user's) todo list:
- If the signed-in user has the right privileges (i.e. in the right "group"), click on the See All Tasks button to access every users' todo list:
- If the signed-in user does not have the right privileges, clicking on the See All Tasks will give an error:
ℹ️ Did the sample not work for you as expected? Then please reach out to us using the GitHub Issues page.
Were we successful in addressing your learning objective? Consider taking a moment to share your experience with us.
Expand for troubleshooting info
Use Stack Overflow to get support from the community.
Ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before.
Make sure that your questions or comments are tagged with [azure-active-directory dotnet ms-identity adal msal].
If you find a bug in the sample, raise the issue on GitHub Issues.
To provide feedback on or suggest features for Azure Active Directory, visit User Voice page.
Much of the specifics of implementing RBAC with Security Groups is the same with implementing RBAC with App Roles discussed in the previous tutorial. In order to avoid redundancy, here we discuss particular issues, such as groups overage, that might arise with using the groups claim.
To ensure that the token size doesn’t exceed HTTP header size limits, the Microsoft Identity Platform limits the number of object Ids that it includes in the groups claim.
If a user is member of more groups than the overage limit (150 for SAML tokens, 200 for JWT tokens, 6 for single-page applications using implicit flow), then the Microsoft Identity Platform does not emit the group IDs in the groups claim in the token. Instead, it includes an overage claim in the token that indicates to the application to query the MS Graph API to retrieve the user’s group membership.
We strongly advise you use the group filtering feature (if possible) to avoid running into group overages.
- You can use the BulkCreateGroups.ps1 provided in the App Creation Scripts folder to create a large number of groups and assign users to them. This will help test overage scenarios during development. You'll need to enter a user's object ID when prompted by the
BulkCreateGroups.ps1script. If you would like to delete these groups after your testing, run the BulkRemoveGroups.ps1.
When attending to overage scenarios, which requires a call to Microsoft Graph to read the signed-in user's group memberships, your app will need to have the User.Read and GroupMember.Read.All for the getMemberGroups function to execute successfully.
⚠️ For the overage scenario, make sure you have granted Admin Consent for the MS Graph API's GroupMember.Read.All scope for both the Client and the Service apps (see the App Registration steps above).
-
When you run this sample and an overage occurred, then you'd see the
_claim_namesin the home page after the user signs-in. -
We strongly advise you use the group filtering feature (if possible) to avoid running into group overages.
-
In case you cannot avoid running into group overage, we suggest you use the following logic to process groups claim in your token.
- Check for the claim
_claim_nameswith one of the values beinggroups. This indicates overage. - If found, make a call to the endpoint specified in
_claim_sourcesto fetch user’s groups. - If none found, look into the
groupsclaim for user’s groups.
- Check for the claim
You can gain a good familiarity of programming for Microsoft Graph by going through the An introduction to Microsoft Graph for developers recorded session.
Consider the group.guard.ts. Here, we are checking whether the user's ID token has the _claim_names claim with the value groups, which indicates that the user has too many group memberships. If so, we redirect the user to the overage component. There, we initiate a call to MS Graph API's https://graph.microsoft.com/v1.0/me/checkMemberGroups endpoint to query the required list of groups that the user belongs to. Finally we check for the designated group IDs among this list:
@Injectable()
export class GroupGuard extends BaseGuard {
constructor(
@Inject(MSAL_GUARD_CONFIG) protected override msalGuardConfig: MsalGuardConfiguration,
protected override msalBroadcastService: MsalBroadcastService,
protected override authService: MsalService,
protected override location: Location,
protected override router: Router,
) {
super(msalGuardConfig, msalBroadcastService, authService, location, router);
}
override activateHelper(state?: RouterStateSnapshot, route?: ActivatedRouteSnapshot): Observable<boolean | UrlTree> {
let result = super.activateHelper(state, route);
const requiredGroups: string[] = route ? route.data['requiredGroups'] : [];
return result.pipe(
concatMap(() => {
let activeAccount = this.authService.instance.getActiveAccount() as AccountWithGroupClaims;
if (!activeAccount && this.authService.instance.getAllAccounts().length > 0) {
activeAccount = this.authService.instance.getAllAccounts()[0] as AccountWithGroupClaims;
}
// check either the ID token or a non-expired storage entry for the groups membership claim
if (!activeAccount?.idTokenClaims?.groups && !checkGroupsInStorage(activeAccount)) {
if (activeAccount.idTokenClaims?._claim_names && activeAccount.idTokenClaims?._claim_names.groups) {
window.alert('You have too many group memberships. The application will now query Microsoft Graph to check if you are a member of any of the groups required.');
return this.router.navigate(['/overage']);
}
window.alert('Token does not have groups claim. Please ensure that your account is assigned to a security group and then sign-out and sign-in again.');
return of(false);
}
// code omitted for brevity...
})
);
}
}In app-routing.module.ts, we add GroupGuard to routes we want to check for group membership:
const routes: Routes = [
{
path: 'todo-view',
component: TodoViewComponent,
canActivate: [
GroupGuard
],
data: {
requiredGroups: [groups.groupMember, groups.groupAdmin]
}
},
{
path: 'dashboard',
component: DashboardComponent,
canActivate: [
GroupGuard,
],
data: {
requiredGroups: [groups.groupAdmin]
}
},
{
path: 'overage',
component: OverageComponent,
canActivate: [
BaseGuard,
]
},
];- In Startup.cs,
OnTokenValidatedevent calls ProcessAnyGroupsOverage method defined in GraphHelper.cs to process groups overage claim.
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(options =>
{
// code omitted for brevity...
options.Events.OnTokenValidated = async context =>
{
// code omitted for brevity...
if (context != null)
{
// Calls method to process groups overage claim (before policy checks kick-in)
await GraphHelper.ProcessAnyGroupsOverage(context, requiredGroupsIds);
}
await Task.CompletedTask;
};
}, options =>
{
Configuration.Bind("AzureAd", options);
}, "Bearer", true)
.EnableTokenAcquisitionToCallDownstreamApi(options => Configuration.Bind("AzureAd", options))
.AddMicrosoftGraph(Configuration.GetSection("MSGraph"))
.AddInMemoryTokenCaches();AddMicrosoftGraph registers the service for GraphServiceClient. The values for BaseUrl and Scopes defined in GraphAPI section of the appsettings.json.
- In GraphHelper.cs, ProcessAnyGroupsOverage method checks if incoming token contains the Group Overage claim. If so, it will call ProcessUserGroupsForOverage method to retrieve groups, which in turn calls the Microsoft Graph
/checkMemberGroupsendpoint.
public static async Task ProcessAnyGroupsOverage(TokenValidatedContext context)
{
// Checks if the incoming token containes a groups overage claim.
if (HasOverageOccurred(context.Principal))
{
await ProcessUserGroupsForOverage(context, requiredGroupsIds);
}
}Since overaged tokens will not contain group membership IDs, yet these IDs are required for controlling access to pages and/or resources, applications have to call Microsoft Graph whenever a user action (e.g. accessing a page on the UI, accessing a todolist item in the web API etc.) takes place. These network calls are costly and will impact the application performance and user experience. As such, both the SPA and web API projects here would benefit from caching the group membership IDs once they are fetched from Microsoft Graph for the first time. By default, these are cached for 1 hour in the sample. Cached groups will miss any changes to a users group membership for this duration. If you need more fine grained control, you can configure cache duration in auth-config.ts for the SPA and in appsettings.json for the web API. If your scenario requires capturing real-time changes to a user's group membership, consider implementing Microsoft Graph change notifications instead.
The ASP.NET middleware supports roles populated from claims by specifying the claim in the RoleClaimType property of TokenValidationParameters. Since the groups claim contains the object IDs of the security groups than the actual names by default, you'd use the group IDs instead of group names. See Role-based authorization in ASP.NET Core for more info. See Startup.cs for more.
// The following lines code instruct the asp.net core middleware to use the data in the "groups" claim in the [Authorize] attribute and for User.IsInrole()
// See https://docs.microsoft.com/aspnet/core/security/authorization/roles
services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
// Use the groups claim for populating roles
options.TokenValidationParameters.RoleClaimType = "groups";
});
// Adding authorization policies that enforce authorization using Azure AD roles.
services.AddAuthorization(options =>
{
options.AddPolicy(AuthorizationPolicies.AssignmentToGroupMemberGroupRequired, policy => policy.RequireRole(Configuration["AzureAd:Groups:GroupMember"], Configuration["AzureAd:Groups:GroupAdmin"]));
options.AddPolicy(AuthorizationPolicies.AssignmentToGroupAdminGroupRequired, policy => policy.RequireRole(Configuration["AzureAd:Groups:GroupAdmin"]));
});These policies can be used in controllers as shown below:
// GET: api/todolist/getAll
[HttpGet]
[Route("getAll")]
[RequiredScope(RequiredScopesConfigurationKey = "AzureAd:Scopes")]
[Authorize(Policy = AuthorizationPolicies.AssignmentToGroupAdminGroupRequired)]
public async Task<ActionResult<IEnumerable<TodoItem>>> GetAll()
{
return await _context.TodoItems.ToListAsync();
}Learn how to Protect and call an API using App Roles.
If you'd like to contribute to this sample, see CONTRIBUTING.MD.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.




