This guide describes how to set up automation for managing B2B guest users (create, delete, disable) and group membership in Azure Entra, including all required API permissions, administrator roles, and step-by-step instructions.
Typical automation needs:
Best-practice approach:
Create an app registration in Azure Entra ID and use Microsoft Graph API with the minimum required Application permissions.
To support all of the above actions, your app requires:
| Functionality | Microsoft Graph Permission | Type |
|---|---|---|
| Invite guests | User.Invite.All |
Application |
| Create/Update/Delete | User.ReadWrite.All |
Application |
| Add/Remove from group | GroupMember.ReadWrite.All |
Application |
All permissions should be added as ‘Application’ type (not ‘Delegated’).
contoso-provisionerAccounts in this organizational directory onlyUser.Invite.AllUser.ReadWrite.AllGroupMember.ReadWrite.AllAdd permissions to your application
Configure permissions to call Graph API (Quickstart)
See the section “Assign Microsoft Graph permissions to the app registration”.
Grant admin consent in the Azure portal
Grant admin consent
You can now fully automate, via MS Graph API:
POST /invitationsPATCH /users/{id} with { "accountEnabled": false }DELETE /users/{id}POST /groups/{group-id}/members/$refDELETE /groups/{group-id}/members/{directoryObject-id}/$ref| Operation | Required Permission (Application) | Consent Required By |
|---|---|---|
| Invite guest user | User.Invite.All | Global/Privileged Admin |
| Update/Delete/Disable | User.ReadWrite.All | Global/Privileged Admin |
| Add/Remove to group | GroupMember.ReadWrite.All | Global/Privileged Admin |
Invite a Guest:
POST https://graph.microsoft.com/v1.0/invitations
{
"invitedUserEmailAddress": "user@example.com",
"inviteRedirectUrl": "https://your-app-url",
"sendInvitationMessage": false
}
Block/Disable a User:
PATCH https://graph.microsoft.com/v1.0/users/{id}
{
"accountEnabled": false
}
Delete a User:
DELETE https://graph.microsoft.com/v1.0/users/{id}
Add a User to a Group:
POST https://graph.microsoft.com/v1.0/groups/{group-id}/members/$ref
Content-Type: application/json
{
"@odata.id": "https://graph.microsoft.com/v1.0/users/{user-id}"
}
Remove a User from a Group:
DELETE https://graph.microsoft.com/v1.0/groups/{group-id}/members/{user-id}/$ref
Q: Does the app need a Directory role?
A: No, it only needs the permissions above with admin consent.
Q: Can I restrict this app to only certain users or groups?
A: You can scope its usage through Conditional Access or App Role Assignments, but with these permissions, the app can manage all user/group objects in the tenant.
Q: Can I use Delegated permissions instead?
A: For backend automation/scenarios with no user login context, use “Application” permissions.
This guide ensures your app has exactly what it needs—and nothing more—to securely provision, deprovision, disable, and group-manage Entra ID users and guests for business automation scenarios like “Contoso App ↔️ Keycloak ↔️ Entra ↔️ Power BI”.