azureblog.co.uk
← cd ~/graph-permissions
// graph-permissions · Directory

Directory.ReadWrite.AllMicrosoft Graph permission · Critical risk

Allows the app to read and write data in your organization's directory, such as users, and groups, without a signed-in user. Does not allow user or group deletion.

Application permission

Critical risk

Read and write directory data. Allows the app to read and write data in your organization's directory, such as users, and groups, without a signed-in user. Does not allow user or group deletion.

ID19dbc75e-c2e2-444c-a770-ec69d8559fc7
ConsentAlways needs admin consent
RiskCan be used to take over the tenant or grant itself more access. Grant only to tightly controlled, well-known apps.

Delegated permission

Critical risk

Read and write directory data. Allows the app to read and write data in your organization's directory, such as users, and groups. It does not allow the app to delete users or groups, or reset user passwords.

IDc5366453-9fb0-48a5-a156-24f0c49a4b84
ConsentNeeds admin consent
RiskCan be used to take over the tenant or grant itself more access. Grant only to tightly controlled, well-known apps.

Least-privilege alternative

Use specific write permissions such as User.ReadWrite.All or GroupMember.ReadWrite.All, scoped to what the app changes.

Grant it to an app

In the portal: App registrations › your app › API permissions › Add a permission › Microsoft Graph › Application permissions, then grant admin consent. Or with Graph PowerShell:

powershell5 lines
Connect-MgGraph -Scopes "Application.Read.All", "AppRoleAssignment.ReadWrite.All"
$graph = Get-MgServicePrincipal -Filter "appId eq '00000003-0000-0000-c000-000000000000'"
$app   = Get-MgServicePrincipal -Filter "appId eq '<your app's client id>'"
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $app.Id `
    -PrincipalId $app.Id -ResourceId $graph.Id -AppRoleId "19dbc75e-c2e2-444c-a770-ec69d8559fc7"

Ask for it when signing in

Delegated permissions act as the signed-in user, so the app can never do more than that user can.

powershell1 line
Connect-MgGraph -Scopes "Directory.ReadWrite.All"

Which apps already have it?

powershell6 lines
# Apps that hold Directory.ReadWrite.All as an application permission
Connect-MgGraph -Scopes "Application.Read.All"
$graph = Get-MgServicePrincipal -Filter "appId eq '00000003-0000-0000-c000-000000000000'"
Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $graph.Id -All |
    Where-Object AppRoleId -eq "19dbc75e-c2e2-444c-a770-ec69d8559fc7" |
    Select-Object PrincipalDisplayName, PrincipalId, CreatedDateTime
powershell6 lines
# Apps with delegated consent for Directory.ReadWrite.All
Connect-MgGraph -Scopes "Application.Read.All", "Directory.Read.All"
$graph = Get-MgServicePrincipal -Filter "appId eq '00000003-0000-0000-c000-000000000000'"
Get-MgOauth2PermissionGrant -All |
    Where-Object { $_.ResourceId -eq $graph.Id -and ($_.Scope -split " ") -contains "Directory.ReadWrite.All" } |
    Select-Object ClientId, ConsentType, PrincipalId

Other Directory permissions

Check every app in your tenant → Permission explainer