1. Home
  2. Lab library
  3. IB-WORKLOAD

Lock Down App Consent and Review OAuth Grants in Entra ID

Consent phishing tricks a user into granting a malicious app access to their mailbox and files, with no password stolen and no MFA prompt to stop it. In this lab you restrict what users can consent to, enable the admin consent workflow, then audit and remove…

Level Intermediate Time about 80 minutes Updated
Quick answer

Consent phishing tricks a user into granting a malicious app access to their mailbox and files, with no password stolen and no MFA prompt to stop it. In this lab you restrict what users can consent to, enable the admin consent workflow, then audit and remove risky OAuth permission grants using Microsoft Graph PowerShell.

Key takeaways

  • A consent grant keeps working after a password reset, so it must be revoked separately
  • Limit user consent to verified publishers and low-impact permissions
  • The admin consent workflow gives users a route to ask instead of a dead end
  • Review tenant-wide grants and high-impact scopes such as Mail.ReadWrite first

Why this lab matters

When a user clicks Accept on a permissions prompt, an application receives a token that can read mail, files or the directory on that user's behalf. If the app is malicious, the attacker now has access that survives a password change and never triggers MFA. Default settings in many tenants still let any user consent to any app. This lab closes that door and cleans up what is already there.

Consent governance, from settings to a clean grant list01Restrict user consentVerified publishers only02Enable workflowRequests go to reviewers03Audit grantsDelegated and application04Remove risky grantsRevoke and disable05Review regularlyMonthly export
Consent governance, from settings to a clean grant list

What you need

  • A test tenant and the Global Administrator or Privileged Role Administrator role.
  • The Microsoft Graph PowerShell SDK.
  • One test user, and one or two enterprise applications with consented permissions. Graph Explorer is an easy one to consent to for test data.
  1. In the Entra admin centre go to Identity, Applications, Enterprise applications, Consent and permissions, User consent settings.
  2. Choose Allow user consent for apps from verified publishers, for selected permissions. For the strictest position choose Do not allow user consent.
  3. Open Permission classifications and review the low-impact list. Keep it small: openid, profile, email, offline_access and User.Read are the usual set.
  4. Save.
  1. In the same area open Admin consent settings.
  2. Set Users can request admin consent to apps they are unable to consent to to Yes.
  3. Add at least two reviewers. Choose people who can judge permissions, not only a shared mailbox.
  4. Turn on email notifications and reminders, set the request expiry to 30 days and save.

Test it: sign in as the test user and open an app that needs a permission outside the low-impact list. You should see Approval required with a box to give a reason. The request then appears under Enterprise applications, Admin consent requests.

Step 3: Audit delegated grants

Connect-MgGraph -Scopes "Directory.Read.All", "DelegatedPermissionGrant.Read.All"

$risky = 'Mail.Read','Mail.ReadWrite','Mail.Send','MailboxSettings.ReadWrite',
         'Files.Read.All','Files.ReadWrite.All','Sites.ReadWrite.All',
         'Directory.ReadWrite.All','User.ReadWrite.All','full_access_as_user'

$grants = Get-MgOauth2PermissionGrant -All | ForEach-Object {
  $sp = Get-MgServicePrincipal -ServicePrincipalId $_.ClientId -Property DisplayName, AppOwnerOrganizationId, VerifiedPublisher
  $scopes = $_.Scope.Trim() -split '\s+'
  [pscustomobject]@{
    App        = $sp.DisplayName
    Publisher  = $sp.VerifiedPublisher.DisplayName
    ConsentFor = if ($_.ConsentType -eq 'AllPrincipals') { 'Whole tenant' } else { 'One user' }
    Risky      = ($scopes | Where-Object { $_ -in $risky }) -join ', '
    Scopes     = $scopes -join ', '
    GrantId    = $_.Id
  }
}
$grants | Sort-Object { $_.Risky.Length } -Descending | Format-Table App, Publisher, ConsentFor, Risky
$grants | Export-Csv .\delegated-grants.csv -NoTypeInformation

Read the top of the list first. An app with no verified publisher, consent for one user and mail or file scopes is the classic consent phishing pattern.

Step 4: Audit application permissions

Application permissions act without a user and are often more powerful.

$graph = Get-MgServicePrincipal -Filter "appId eq '00000003-0000-0000-c000-000000000000'"
Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $graph.Id -All | ForEach-Object {
  $role = $graph.AppRoles | Where-Object Id -eq $_.AppRoleId
  [pscustomobject]@{ App = $_.PrincipalDisplayName; Permission = $role.Value; Granted = $_.CreatedDateTime }
} | Sort-Object App | Format-Table

Question anything ending in .ReadWrite.All, and treat RoleManagement.ReadWrite.Directory and AppRoleAssignment.ReadWrite.All as equivalent to Global Administrator.

Step 5: Remove a risky grant

  1. Confirm with the user or owner that the app is not needed.
  2. Revoke the grant:
    Connect-MgGraph -Scopes "DelegatedPermissionGrant.ReadWrite.All"
    Remove-MgOauth2PermissionGrant -OAuth2PermissionGrantId "<GrantId from the report>"
  3. If the app looks malicious, also open it under Enterprise applications, Properties, and set Enabled for users to sign in to No. Then revoke the affected user's sessions.
Warning

A password reset alone does not remove an app's access. The grant and any refresh tokens must be revoked.

Verify

You are done when a standard user sees the approval request screen for a non-listed permission, the request reaches a reviewer, and your grant report no longer shows the app you removed.

Evidence to keep

  • Screenshots of the user consent and admin consent settings.
  • The delegated grant CSV from before and after.
  • One completed admin consent request showing who approved or denied it.

Clean up

Remove the test apps. Leave the consent settings in place in any tenant you care about.

Frequently asked questions

What is consent phishing?

Consent phishing is an attack where a user is tricked into granting a malicious application OAuth permissions to their data. The attacker gets tokens for mail or files without needing the user's password or MFA.

Does resetting a password remove an app's access?

No. An OAuth consent grant and its refresh tokens stay valid after a password reset. You must remove the permission grant and revoke the user's sessions.

What is the admin consent workflow in Entra ID?

It is a setting that lets users request approval for an app they are not allowed to consent to. Named reviewers receive the request, see the permissions and approve or deny it.

Which OAuth permissions are high risk?

Scopes that read or change mail, files or the directory across many users, such as Mail.ReadWrite, Files.ReadWrite.All and Directory.ReadWrite.All, plus application permissions that can grant roles, such as RoleManagement.ReadWrite.Directory.

Built and published by Muhammad Rizwan Afzal for Identity Bytes. Run every lab against a disposable test tenant, never production.