| title | Grant an appRoleAssignment for a service principal |
|---|---|
| description | Grant an app role assignment for a service principal. |
| ms.localizationpriority | high |
| doc_type | apiPageType |
| ms.subservice | entra-applications |
| author | psignoret |
| ms.date | 08/14/2024 |
Namespace: microsoft.graph
Assign an app role for a resource service principal, to a user, group, or client service principal.
App roles that are assigned to service principals are also known as application permissions. Application permissions can be granted directly with app role assignments, or through a consent experience.
To grant an app role assignment, you need three identifiers:
principalId: Theidof the user, group or client servicePrincipal to which you are assigning the app role.resourceId: Theidof the resource servicePrincipal which has defined the app role.appRoleId: Theidof the appRole (defined on the resource service principal) to assign to a user, group, or service principal.
[!INCLUDE national-cloud-support]
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.
[!INCLUDE permissions-table]
[!INCLUDE rbac-approleassignments-apis-write]
You can address the service principal using either its id or appId. id and appId are referred to as the Object ID and Application (Client) ID, respectively, in app registrations in the Microsoft Entra admin center.
POST /servicePrincipals/{id}/appRoleAssignedTo
POST /servicePrincipals(appId='{appId}')/appRoleAssignedTo| Name | Description |
|---|---|
| Authorization | Bearer {token}. Required. Learn more about authentication and authorization. |
| Content-type | application/json. Required. |
In the request body, supply a JSON representation of an appRoleAssignment object.
If successful, this method returns a 201 Created response code and an appRoleAssignment object in the response body.
The following example shows a request.
POST https://graph.microsoft.com/v1.0/servicePrincipals/9028d19c-26a9-4809-8e3f-20ff73e2d75e/appRoleAssignedTo
Content-Type: application/json
{
"principalId": "33ad69f9-da99-4bed-acd0-3f24235cb296",
"resourceId": "9028d19c-26a9-4809-8e3f-20ff73e2d75e",
"appRoleId": "ef7437e6-4f94-4a0a-a110-a439eb2aa8f7"
}[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
In this example, {id} and {resourceId-value} would both be the id of the resource service principal, and {principalId} would be the id of the assigned user, group, or client service principal.
The following example shows the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#servicePrincipals('9028d19c-26a9-4809-8e3f-20ff73e2d75e')/appRoleAssignedTo/$entity",
"id": "-WmtM5na7Uus0D8kI1yylpU9Mdo0Pb9OoBJvd3T5eKc",
"deletedDateTime": null,
"appRoleId": "ef7437e6-4f94-4a0a-a110-a439eb2aa8f7",
"createdDateTime": "2021-02-15T16:14:59.8643039Z",
"principalDisplayName": "Parents of Contoso",
"principalId": "33ad69f9-da99-4bed-acd0-3f24235cb296",
"principalType": "Group",
"resourceDisplayName": "Fabrikam App",
"resourceId": "9028d19c-26a9-4809-8e3f-20ff73e2d75e"
}