Skip to content

Latest commit

 

History

History
163 lines (118 loc) · 6.69 KB

File metadata and controls

163 lines (118 loc) · 6.69 KB
title Grant an appRoleAssignment to a service principal
description Grant an app role assignment to a service principal.
ms.localizationpriority high
doc_type apiPageType
ms.subservice entra-applications
author psignoret
ms.date 07/26/2024

Grant an appRoleAssignment to a service principal

Namespace: microsoft.graph

[!INCLUDE beta-disclaimer]

Assign an app role to a 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 to a client service principal, you need three identifiers:

  • principalId: The id of the client service principal to which you are assigning the app role.
  • resourceId: The id of the resource servicePrincipal (the API) which has defined the app role (the application permission).
  • appRoleId: The id of the appRole (defined on the resource service principal) to assign to the client service principal.

[!INCLUDE national-cloud-support]

Permissions

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]

HTTP request

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}/appRoleAssignments
POST /servicePrincipals(appId='{appId}')/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. Learn more about authentication and authorization.
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

The following example shows a request.

POST https://graph.microsoft.com/beta/servicePrincipals/9028d19c-26a9-4809-8e3f-20ff73e2d75e/appRoleAssignments
Content-Type: application/json

{
  "principalId": "9028d19c-26a9-4809-8e3f-20ff73e2d75e",
  "resourceId": "8fce32da-1246-437b-99cd-76d1d4677bd5",
  "appRoleId": "498476ce-e0fe-48b0-b801-37ba7e2685c6"
}

[!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 service principal id in the request URL (9028d19c-26a9-4809-8e3f-20ff73e2d75e) is the same as the principalId property in the body. The resourceId value is the id of the resource service principal (the API).

Response

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/beta/$metadata#appRoleAssignments/$entity",
  "id": "2jLOj0YSe0OZzXbR1Gd71fDqFUrPM1xIgUfvWBHJ9n0",
  "creationTimestamp": "2021-02-15T16:39:38.2975029Z",
  "appRoleId": "498476ce-e0fe-48b0-b801-37ba7e2685c6",
  "principalDisplayName": "Fabrikam App",
  "principalId": "9028d19c-26a9-4809-8e3f-20ff73e2d75e",
  "principalType": "ServicePrincipal",
  "resourceDisplayName": "Microsoft Graph",
  "resourceId": "8fce32da-1246-437b-99cd-76d1d4677bd5"
}