A cloud-based identity and access management service for securing user authentication and resource access
Microsoft Graph v1.0 can provide the centralized mechanism, using the Enterprise Application’s service principal object ID and its appRoleAssignedTo relationship for assignments, plus appRoles for tenant-local role definitions.
Delegated-only automation must run with a signed-in work or school user—through interactive authentication or an on-behalf-of flow. It is not suitable for a fully unattended daemon with no user context because delegated permissions act on behalf of a signed-in user.^1^
1. Permissions and operator roles
Request only the delegated scopes required by each function:
| Operation | Delegated permission |
|---|---|
| Find/read service principals and roles | Application.Read.All |
| List assignments for an Enterprise Application | Application.Read.All |
| Create/delete assignments | AppRoleAssignment.ReadWrite.All |
| Create/update/delete service-principal app roles | Application.ReadWrite.All |
Reading a service principal uses Application.Read.All.^2^ Assignment writes use AppRoleAssignment.ReadWrite.All; the signed-in user must also hold a supported Entra role. For assignment operations, Privileged Role Administrator is the least-privileged role identified specifically for Microsoft Graph app-role administration, although several other administrative roles are supported.^3^
For tenant-local Enterprise Application role creation, Microsoft’s procedure specifically requires a Privileged Role Administrator. Its Graph Explorer instructions request both Application.ReadWrite.All and Directory.ReadWrite.All, while the underlying update-servicePrincipal API identifies Application.ReadWrite.All as the least-privileged delegated permission. For a custom client, start with the API’s least-privileged permission and add broader permission only if another operation requires it.^4^^5^
2. Resolve the Enterprise Application
An Enterprise Application is represented by a service principal. Resolve it by application/client ID:
GET https://graph.microsoft.com/v1.0/servicePrincipals(appId='{application-client-id}')?$select=id,appId,displayName,appRoles,appRoleAssignmentRequired
Authorization: Bearer {delegated-token}
Keep the returned id; it is the service principal object ID, not the application/client ID.
3. List, add, and remove assignments
List all direct assignments to the application:
GET https://graph.microsoft.com/v1.0/servicePrincipals/{resource-sp-id}/appRoleAssignedTo
Authorization: Bearer {delegated-token}
This returns assignments whose principals can be users, groups, or service principals.^6^ Follow every @odata.nextLink until absent. Group entries represent group assignments; they are not expanded into every user who receives effective access through membership.
Assign a user:
POST https://graph.microsoft.com/v1.0/servicePrincipals/{resource-sp-id}/appRoleAssignedTo
Authorization: Bearer {delegated-token}
Content-Type: application/json
{
"principalId": "{user-object-id}",
"resourceId": "{resource-sp-id}",
"appRoleId": "{app-role-id}"
}
The payload requires principalId, resourceId, and appRoleId.^7^ If the application exposes no explicit roles and supports assignment without a role, use the default-access role ID:
00000000-0000-0000-0000-000000000000
Remove the assignment using the assignment object’s id:
DELETE https://graph.microsoft.com/v1.0/servicePrincipals/{resource-sp-id}/appRoleAssignedTo/{assignment-id}
Authorization: Bearer {delegated-token}
Success returns 204 No Content. Microsoft recommends deleting through the resource service principal’s appRoleAssignedTo relationship.^8^
Deleting an assignment removes that assignment. It blocks application sign-in only when the Enterprise Application has appRoleAssignmentRequired=true, or when another authorization layer enforces equivalent restrictions. Changing this property affects sign-in behavior, so enable it only when assigned-user-only access is intended:
PATCH https://graph.microsoft.com/v1.0/servicePrincipals/{resource-sp-id}
Authorization: Bearer {delegated-token}
Content-Type: application/json
{ "appRoleAssignmentRequired": true }
4. Create or update tenant-local app roles
First GET the complete appRoles collection. Append a new role or modify the required existing object, then PATCH the entire resulting collection:
PATCH https://graph.microsoft.com/v1.0/servicePrincipals/{resource-sp-id}
Authorization: Bearer {delegated-token}
Content-Type: application/json
{
"appRoles": [{
"allowedMemberTypes": ["User"],
"description": "Approves business requests",
"displayName": "Approver",
"id": "11111111-2222-3333-4444-555555555555",
"isEnabled": true,
"origin": "ServicePrincipal",
"value": "Approver"
}]
}
The example shows one role for brevity; the actual PATCH must include every existing role that must remain. Omitting existing entries removes them from the collection.^5^
To delete a role safely:
- GET and retain the complete
appRolesarray. - PATCH the complete array with the target role’s
isEnabledset tofalse. - PATCH again with only that disabled role removed.
- Preserve every other role unchanged.
For custom applications where roles should be part of the application’s durable definition rather than tenant-local customization, manage them on the backing app registration instead; the service-principal procedure above specifically manages Enterprise Application-local roles.
References