| title | Grant an appRoleAssignment to a user |
|---|---|
| description | Grant an app role assignment to a user. |
| ms.localizationpriority | high |
| doc_type | apiPageType |
| ms.subservice | entra-users |
| author | psignoret |
| ms.date | 10/15/2024 |
Namespace: microsoft.graph
Assign an app role to a user, creating an appRoleAssignment object. To grant an app role assignment to a user, you need three identifiers:
principalId: Theidof the user to whom you are assigning the app role.resourceId: Theidof the resourceservicePrincipalthat has defined the app role.appRoleId: Theidof theappRole(defined on the resource service principal) to assign to the user.
[!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]
POST /users/{id | userPrincipalName}/appRoleAssignmentsNote
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.
| 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/users/cde330e5-2150-4c11-9c5b-14bfdc948c79/appRoleAssignments
Content-Type: application/json
{
"principalId": "cde330e5-2150-4c11-9c5b-14bfdc948c79",
"resourceId": "8e881353-1735-45af-af21-ee1344582a4d",
"appRoleId": "00000000-0000-0000-0000-000000000000"
}[!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, note that the value used as the user id in the request URL (cde330e5-2150-4c11-9c5b-14bfdc948c79) is the same as the principalId property in the body.
The following example shows the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('cde330e5-2150-4c11-9c5b-14bfdc948c79')/appRoleAssignments/$entity",
"id": "5TDjzVAhEUycWxS_3JSMeY-oHkjrWvBKi7aIZwYGQzg",
"deletedDateTime": null,
"appRoleId": "00000000-0000-0000-0000-000000000000",
"createdDateTime": "2021-02-15T10:31:53.5164841Z",
"principalDisplayName": "Megan Bowen",
"principalId": "cde330e5-2150-4c11-9c5b-14bfdc948c79",
"principalType": "User",
"resourceDisplayName": "dxprovisioning-graphapi-client",
"resourceId": "8e881353-1735-45af-af21-ee1344582a4d"
}