Grant an appRoleAssignment to a user
Namespace: microsoft.graph
Important
APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Use this API to assign an app role to a user. 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.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
| Permission type | Permissions (from least to most privileged) |
|---|---|
| Delegated (work or school account) | AppRoleAssignment.ReadWrite.All |
| Delegated (personal Microsoft account) | Not supported. |
| Application | AppRoleAssignment.ReadWrite.All |
HTTP request
POST /users/{id | userPrincipalName}/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.
Request headers
| Name | Description |
|---|---|
| Authorization | Bearer {token}. Required. |
| Content-Type | application/json. Required. |
Request body
In the request body, supply a JSON representation of an appRoleAssignment object.
Response
If successful, this method returns a 201 Created response code and an appRoleAssignment object in the response body.
Examples
Request
Here is an example of the request.
POST https://graph.microsoft.com/beta/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"
}
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.
Response
Here is an example of 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/beta/$metadata#users('cde330e5-2150-4c11-9c5b-14bfdc948c79')/appRoleAssignments/$entity",
"id": "5TDjzVAhEUycWxS_3JSMeY-oHkjrWvBKi7aIZwYGQzg",
"deletedDateTime": null,
"appRoleId": "00000000-0000-0000-0000-000000000000",
"creationTimestamp": "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"
}
Feedback
Submit and view feedback for