Skip to content

LearnIdentity

Device code and app consent controls review

Brief

Device code phishing and consent phishing both get a user to approve a real Microsoft prompt, so the defence is tenant configuration, not user training alone: block the flow where nobody needs it, limit who can consent to which apps, and watch the logs that record both. This review reads those controls and the grants users have already made, and never runs either flow against anyone.

Stage
Access
Reviewed
On this page
  1. Check first
  2. Does a Conditional Access policy block device code flow?
  3. Who signs in with device code today?
  4. Can users consent to apps, and does admin consent work?
  5. Which apps have users already consented to, and with what?
  6. Which log fields show these flows?
  7. The defender sees
  8. Done when
  9. Not covered
  10. Tools
  11. Related research
  12. Where this page fits
  13. Reviewed

All commands

Situation
A read-only review identity with Global Reader and Microsoft Graph PowerShell consented for Policy.Read.All, Directory.Read.All and AuditLog.Read.All, and read access to the Log Analytics workspace that holds Entra sign-in and audit logs. Every step is a read of configuration, grants or logs in the tenant the scope letter names; we do not start a device code sign-in, register an app or ask anyone to consent.
Goal
A controls table: the device code policy and its state, current device code use by app, the user consent setting, the admin consent workflow, every app users consented to with its publisher and permissions, and the log fields a detection needs.
Outputs
Representative examples on placeholder hosts, trimmed to the lines that matter. Not captured from a public fixture yet.

Check first

  • Which devices and tools genuinely use device code sign-in, such as meeting room devices, shared displays and command line tools, from the client's own inventory.
  • Whether sign-in and audit logs reach a Log Analytics workspace, and for how long.
  • The client's approved app list, so consented apps can be compared against it.
  • Who reviews admin consent requests today, if anyone.

Steps

Does a Conditional Access policy block device code flow?

Connect-MgGraph -Scopes 'Policy.Read.All','Directory.Read.All','AuditLog.Read.All' -NoWelcome
Get-MgIdentityConditionalAccessPolicy -All | Where-Object { $_.Conditions.AuthenticationFlows.TransferMethods } |
  Select-Object DisplayName, State, @{n='Flows';e={$_.Conditions.AuthenticationFlows.TransferMethods}},
    @{n='ExcludedGroups';e={$_.Conditions.Users.ExcludeGroups.Count}}

Expected output

DisplayName                  State                              Flows          ExcludedGroups
-----------                  -----                              -----          --------------
CA020 Block device code flow enabledForReportingButNotEnforced deviceCodeFlow              1   # <- report-only: nothing is blocked

The authentication flows condition targets device code and authentication transfer. A policy that blocks deviceCodeFlow for all users, with an exclusion group for the devices that need it, is the control. Report-only logs what would have been blocked and blocks nothing.

Negative result. One enabled policy blocks device code flow for all users and apps, with a reviewed exclusion group scoped to named devices and locations.

Fix. Turn the policy on after a report-only period, keep the exclusion group small and owned, and limit excluded sign-ins to named locations.

Who signs in with device code today?

SigninLogs
| where TimeGenerated > ago(30d) and AuthenticationProtocol == "deviceCode"
| summarize SignIns = count(), Users = dcount(UserPrincipalName) by AppDisplayName, ResultType

Expected output

AppDisplayName       ResultType  SignIns  Users
Microsoft Azure CLI  0           41       3
Microsoft Office     0           212      57   # <- 57 people completing device code into Office: not a known use
Microsoft Teams      0           1880     12

AuthenticationProtocol records deviceCode for these sign-ins, so the query gives the real use the block has to allow for. A handful of engineers using a command line tool and a dozen room devices are expected; dozens of ordinary users signing in to Office this way is not. We report counts by app, never names.

Negative result. Device code use limited to the apps and accounts in the client's inventory.

Fix. Move command line users to browser or broker sign-in, and put room devices in the exclusion group before the block goes live.

(Get-MgPolicyAuthorizationPolicy).DefaultUserRolePermissions.PermissionGrantPoliciesAssigned
Get-MgPolicyAdminConsentRequestPolicy | Select-Object IsEnabled, NotifyReviewers, RequestDurationInDays, @{n='Reviewers';e={$_.Reviewers.Count}}

Expected output

ManagePermissionGrantsForSelf.microsoft-user-default-legacy   # <- any user can consent to any app for permissions that need no admin
ManagePermissionGrantsForOwnedResource.DeveloperConsent

IsEnabled NotifyReviewers RequestDurationInDays Reviewers
--------- --------------- --------------------- ---------
    False           False                    30         0

microsoft-user-default-legacy lets users consent to any app for any permission that does not need an administrator, which includes reading their own mail and files. microsoft-user-default-low allows only apps from verified publishers or registered in the tenant, and only permissions the client classified as low impact. No ManagePermissionGrantsForSelf entry means no user consent. The admin consent workflow gives users a way to ask instead of a dead end.

Negative result. User consent off or set to the low-impact policy, and the admin consent workflow on with named reviewers.

Fix. Set user consent to verified publishers with low-impact permissions, classify those permissions, and enable the admin consent workflow with a reviewer group.

Which apps have users already consented to, and with what?

Get-MgOauth2PermissionGrant -All -Filter "consentType eq 'Principal'" | Group-Object ClientId | ForEach-Object {
  $sp = Get-MgServicePrincipal -ServicePrincipalId $_.Name -Property DisplayName,VerifiedPublisher
  [pscustomobject]@{ App = $sp.DisplayName
    Publisher = if ($sp.VerifiedPublisher.DisplayName) { $sp.VerifiedPublisher.DisplayName } else { 'unverified' }
    Users = $_.Count; Scopes = (($_.Group.Scope -join ' ') -split ' ' | Where-Object { $_ } | Sort-Object -Unique) -join ' ' } } |
  Sort-Object Users -Descending

Expected output

App               Publisher             Users Scopes
---               ---------             ----- ------
Meeting Scheduler Example Meetings Ltd    412 email offline_access openid profile User.Read
PDF Tools Online  unverified               23 Files.Read.All Mail.Read offline_access   # <- an unverified app reading 23 mailboxes and their files

Changing the consent setting affects future consent only; grants already made stay until someone revokes them, so this list is where existing exposure sits. offline_access means the app holds refresh tokens and keeps reading after the user leaves.

Negative result. Every user-consented app is on the approved list, from a verified publisher, with sign-in scopes only.

Fix. Revoke grants for unknown apps, disable their service principals, and review this list each quarter.

Which log fields show these flows?

AuditLogs
| where TimeGenerated > ago(30d) and OperationName == "Consent to application"
| extend App = tostring(TargetResources[0].displayName)
| summarize Consents = count() by App, Result

Expected output

App               Result   Consents
PDF Tools Online  success  23   # <- each consent is an event a rule can alert on

Consent to application in the audit log records each grant, with the app and the user who made it. Device code sign-ins carry deviceCode in AuthenticationProtocol, in interactive and non-interactive sign-in logs. These two fields are what the stolen token page starts from when either control fails.

Negative result. Both queries return, and analytics rules already alert on device code sign-ins outside the exclusion group and on consent to unverified apps.

Fix. Add those two rules, routed to whoever can revoke a grant or a session.

The defender sees

Graph PowerShell sign-ins and directory reads by the review identity, and Log Analytics queries in the workspace's own query audit if it is on. Nothing on this page creates a sign-in, a consent or a grant, so the only new events are our reads.

Done when

The device code policy is found or found missing, device code sign-ins are counted by app, the consent setting and admin consent workflow are read, user-consented apps are listed with publisher, user count and scopes, and both log queries return.

Not covered

Running a device code or consent simulation, Conditional Access beyond the authentication flows condition (see the Conditional Access review), and OAuth flaws in the client's own apps (see the OAuth client review); the outputs shown are representative examples on a placeholder tenant, not captured runs.