Library

Guides Quick Fixes Scripts Find a Guide

Tools

Error Decoder Assessment Baselines Free Tools Service status What's Changed

More

AI Certifications For MSPs Recommended Gear Field Kit FAQ About Contact Get Assessment

Block Device Code Flow with Conditional Access

EntraReady Guides · Practical Microsoft 365 & Entra ID
Last reviewed:
Last verified against Microsoft Learn:

Device code flow lets someone sign in on a device without a keyboard by entering a code on another device. Microsoft calls it a high-risk authentication method that can be part of a phishing attack, and recommends blocking it wherever possible and allowing it only where necessary (Authentication flows (opens in a new tab)). Conditional Access has a dedicated Authentication flows condition for this.

Use it when: you're hardening a tenant against token phishing, or a security review flags device code sign-ins you can't explain.

Before you start

Step by step

  1. Find current use. In Entra ID > Monitoring & health > Sign-in logs, add the Authentication protocol filter and choose device code (Sign-in logs section (opens in a new tab)). Check both interactive and non-interactive tabs. Note which users, apps and devices show up; legitimate uses are usually shared or input-limited devices such as conference room or signage devices.
  2. Check device registration. Since early September 2024, authentication flows policies that target All resources are also enforced on the Device Registration Service. If you use device code flow to register devices, filter the sign-in logs by the Device Registration Service in the Resource ID filter plus the Device code authentication protocol, and exclude that resource from the policy if needed (Enforcement on Device Registration Service (opens in a new tab)).
  3. Create the policy. Entra ID > Conditional Access > Policies > New policy (Device code flow policies (opens in a new tab)):
    • Users: Include All users; Exclude your emergency access accounts and any documented exceptions.
    • Target resources: All resources (formerly 'All cloud apps').
    • Conditions > Authentication Flows: Configure = Yes, select Device code flow, Done.
    • Grant: Block access.
    • Enable policy: Report-only, then Create.
  4. Review report-only results for a week or two, then switch the policy to On (Block authentication flows (opens in a new tab)).
  5. Scope exceptions narrowly. If a device genuinely needs device code flow, Learn's example is to block it everywhere except a specific device platform in a specific network location (Device code flow (opens in a new tab)), rather than excluding whole user groups.
  6. Optional: authentication transfer. The same condition can block Authentication transfer (for example the Outlook desktop QR code that moves a session to a phone) for groups that shouldn't use Outlook on personal devices (Authentication transfer policies (opens in a new tab)).

Read-only PowerShell: which policies already control authentication flows

Read-only. Module: Microsoft.Graph.Identity.SignIns. Scope: Policy.Read.All. Roles supported for this read include Security Reader, Global Reader and Conditional Access Administrator (List policies (opens in a new tab)). Not tested against a live tenant.

Connect-MgGraph -Scopes "Policy.Read.All"
Get-MgIdentityConditionalAccessPolicy -All |
Where-Object { $_.Conditions.AuthenticationFlows.TransferMethods } |
ForEach-Object {
[pscustomobject]@{
Policy          = $_.DisplayName
State           = $_.State
TransferMethods = $_.Conditions.AuthenticationFlows.TransferMethods
IncludeApps     = ($_.Conditions.Applications.IncludeApplications -join '; ')
ExcludeApps     = ($_.Conditions.Applications.ExcludeApplications -join '; ')
ExcludeUsers    = ($_.Conditions.Users.ExcludeUsers -join '; ')
ExcludeGroups   = ($_.Conditions.Users.ExcludeGroups -join '; ')
Grant           = ($_.GrantControls.BuiltInControls -join '; ')
}
} | Export-Csv .\ca-authentication-flows.csv -NoTypeInformation

transferMethods can be none, deviceCodeFlow, authenticationTransfer or unknownFutureValue (conditionalAccessAuthenticationFlows (opens in a new tab)). The v1.0 signIn resource doesn't expose the authentication protocol, so use the portal filter in step 1 to find device code sign-ins.

Gotchas

Check it worked

Roll back

Set the policy to Report-only or Off. Devices that were blocked because of protocol tracking may need to sign in again to get a fresh token.

Related on EntraReady: Conditional Access baseline, Block legacy authentication, Investigate a sign-in with the sign-in logs, Test a policy in report-only first.

← All Guides

Is this still accurate?

Spotted something outdated or wrong on this page? Tell us in a sentence. The page address is sent with it.

Reports go to the EntraReady inbox. Please don’t include passwords or tenant secrets.