Use this API to assign an app role to a security group. All direct members of the group will be considered assigned. Security groups with dynamic memberships are supported. To grant an app role assignment to a group, you need three identifiers:
principalId: The ID of the group to which you are assigning the app role.
resourceId: The ID of the resource servicePrincipal that has defined the app role.
appRoleId: The ID of the appRole (defined on the resource service principal) to assign to the group.
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permission type
Least privileged permissions
Higher privileged permissions
Delegated (work or school account)
AppRoleAssignment.ReadWrite.All
Not available.
Delegated (personal Microsoft account)
Not supported.
Not supported.
Application
AppRoleAssignment.ReadWrite.All
Not available.
Important
In delegated scenarios with work or school accounts, the signed-in user must be assigned a supported Microsoft Entra role or a custom role with a supported role permission. The following least privileged roles are supported for this operation:
Directory Synchronization Accounts - for Microsoft Entra Connect and Microsoft Entra Cloud Sync services
Directory Writer
Hybrid Identity Administrator
Identity Governance Administrator
Privileged Role Administrator
User Administrator
Application Administrator
Cloud Application Administrator
HTTP request
POST /groups/{groupId}/appRoleAssignments
Note
As a best practice, we recommend creating app role assignments through the appRoleAssignedTo relationship of the resource service principal, instead of the appRoleAssignments relationship of the assigned user, group, or service principal.
In the request body, supply a JSON representation of an appRoleAssignment object.
The following table lists the properties that are required when you create the appRoleAssignment. Specify other writable properties as necessary for your appRoleAssignment.
Property
Type
Description
appRoleId
Guid
The identifier (id) for the app role which is assigned to the principal. This app role must be exposed in the appRoles property on the resource application's service principal (resourceId). If the resource application has not declared any app roles, a default app role ID of 00000000-0000-0000-0000-000000000000 can be specified to signal that the principal is assigned to the resource app without any specific app roles.
principalId
Guid
The unique identifier (id) for the group being granted the app role.
resourceId
Guid
The unique identifier (id) for the resource service principal for which the assignment is made.
Response
If successful, this method returns a 201 Created response code and an appRoleAssignment object in the response body.
Examples
Request
The following example shows a request. In this example, ID in the URL and value of principalId would both be the ID of the assigned group.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new AppRoleAssignment
{
PrincipalId = Guid.Parse("7679d9a4-2323-44cd-b5c2-673ec88d8b12"),
ResourceId = Guid.Parse("076e8b57-bac8-49d7-9396-e3449b685055"),
AppRoleId = Guid.Parse("00000000-0000-0000-0000-000000000000"),
};
// To initialize your graphClient, see https://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].AppRoleAssignments.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
"github.com/google/uuid"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewAppRoleAssignment()
principalId := uuid.MustParse("7679d9a4-2323-44cd-b5c2-673ec88d8b12")
requestBody.SetPrincipalId(&principalId)
resourceId := uuid.MustParse("076e8b57-bac8-49d7-9396-e3449b685055")
requestBody.SetResourceId(&resourceId)
appRoleId := uuid.MustParse("00000000-0000-0000-0000-000000000000")
requestBody.SetAppRoleId(&appRoleId)
// To initialize your graphClient, see https://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
appRoleAssignments, err := graphClient.Groups().ByGroupId("group-id").AppRoleAssignments().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
AppRoleAssignment appRoleAssignment = new AppRoleAssignment();
appRoleAssignment.setPrincipalId(UUID.fromString("7679d9a4-2323-44cd-b5c2-673ec88d8b12"));
appRoleAssignment.setResourceId(UUID.fromString("076e8b57-bac8-49d7-9396-e3449b685055"));
appRoleAssignment.setAppRoleId(UUID.fromString("00000000-0000-0000-0000-000000000000"));
AppRoleAssignment result = graphClient.groups().byGroupId("{group-id}").appRoleAssignments().post(appRoleAssignment);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\AppRoleAssignment;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AppRoleAssignment();
$requestBody->setPrincipalId('7679d9a4-2323-44cd-b5c2-673ec88d8b12');
$requestBody->setResourceId('076e8b57-bac8-49d7-9396-e3449b685055');
$requestBody->setAppRoleId('00000000-0000-0000-0000-000000000000');
$result = $graphServiceClient->groups()->byGroupId('group-id')->appRoleAssignments()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.app_role_assignment import AppRoleAssignment
# To initialize your graph_client, see https://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AppRoleAssignment(
principal_id = UUID("7679d9a4-2323-44cd-b5c2-673ec88d8b12"),
resource_id = UUID("076e8b57-bac8-49d7-9396-e3449b685055"),
app_role_id = UUID("00000000-0000-0000-0000-000000000000"),
)
result = await graph_client.groups.by_group_id('group-id').app_role_assignments.post(request_body)