Join our Newsletter — 33% off our NHI Course
Home› Guides› How to block device code flow with Conditional…
Guide Authentication

How to block device code flow with Conditional Access and handle the exceptions: Audit, Block and Scope the Few Legitimate Uses

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 20 November 2026 15 min read
On this page

Blocking device code flow in Microsoft Entra ID takes one Conditional Access policy, but doing it safely means auditing current use first, scoping a small and documented exception, and understanding how protocol tracking can block sessions you did not expect. This how-to walks through that sequence: finding where device code flow is used today, building the block in report-only mode, carving out the exceptions Microsoft documents, switching the policy on, and troubleshooting the blocks that follow.

The attack this policy stops is covered in our Device Code Phishing Guide, and the campaigns that made it a priority are profiled in Storm-2372 (device code phishing) threat actor profile. This page does not repeat that material. It is the procedural companion: the clicks, the exception design and the operating checks.

This is an independent guide from NHI Mgmt Group, based on Microsoft Entra's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft. Product features change, so confirm settings against Microsoft's current documentation.

Key takeaways

  • Microsoft describes device code flow as a high-risk authentication method and recommends blocking it wherever possible, allowing it only where necessary.
  • The control lives in Conditional Access under Conditions > Authentication Flows, with two options: Device code flow and Authentication transfer.
  • Start in Report-only, filter sign-in logs by the Authentication Protocol filter, and only then move the policy to On.
  • If the policy targets all resources and you use device code flow for device registration, exclude the Device Registration Service (client ID 01cb2876-7ebd-4aa4-9cc9-d28bd4d359a9).
  • Sessions that used device code flow are protocol tracked. Later requests in the same session can be blocked even when they do not use device code flow, and Microsoft treats that as expected behaviour.
  • Exclude emergency access accounts and keep every other exception narrow: a named group, specific devices, a specific network location, and an owner who reviews it.

What device code flow is and why it is blocked

The OAuth 2.0 device authorization grant, defined in IETF RFC 8628, lets a device with limited input, such as a smart TV, printer or media console, obtain authorisation by showing the user a short code and a verification address. The user completes sign-in on a second device such as a phone or laptop, while the original device polls the authorisation server until approval arrives.

The same property that makes the flow convenient makes it easy to abuse. RFC 8628 itself warns that the flow can be initiated on a device in an attacker's possession, recommends telling the user that they are authorising a device, and notes that short code lifetimes limit the viability of codes sent over email or text message. In practice the user signs in on a genuine Microsoft page with their own MFA, and the tokens land with whoever started the flow.

Microsoft's authentication flows documentation states that device code flow lets you sign into devices that lack local input devices, like shared devices or digital signage, and that it is a high-risk authentication method that can be part of a phishing attack or used to access corporate resources on unmanaged devices. Its recommendation is direct: allow device code flow only where necessary, and block it wherever possible.

The token theft that follows maps to MITRE ATT&CK: Steal Application Access Token (T1528) and, once the tokens are used, to MITRE ATT&CK: Valid Accounts: Cloud Accounts (T1078.004). Blocking the flow removes the initial token issuance, which is cheaper than detecting every replay afterwards.

Before you start: roles, scope and the second flow

Microsoft's block authentication flows procedure requires you to sign in to the Microsoft Entra admin center as at least a Conditional Access Administrator. Use a dedicated admin account for this, not a daily driver account, and make sure your emergency access accounts are known and tested before you create any blocking policy.

The Authentication Flows condition covers two flows, and it helps to decide on both at the same time:

  • Device code flow: the OAuth device authorization grant described above.
  • Authentication transfer: a flow that lets users transfer authenticated state from one device to another. Microsoft gives the example of a QR code in desktop Outlook that, when scanned on a mobile device, transfers the user's authenticated state to that device.

Microsoft documents a separate procedure for blocking authentication transfer if you do not want users to move authentication from a PC to a mobile device. That is a usability decision as much as a security one, so this guide treats it as optional and keeps it in its own policy. Mixing both flows in one policy makes report-only results harder to read and exceptions harder to reason about.

Decide on scope as well. Microsoft's procedure recommends All users and All resources (formerly 'All cloud apps'). A tenant-wide block is the strongest position and the easiest to explain, but it triggers the Device Registration Service consideration covered below and makes protocol tracking effects tenant-wide.

Step 1: Find out who uses device code flow today

Microsoft advises that before you restrict or block device code flow you should understand if and how it is used in your organisation, either by creating the policy in report-only mode or by filtering sign-in logs for device code flow events with the authentication protocol filter. Do both: the log filter gives you history now, and report-only gives you a forward view of exactly what the policy would block.

A practical audit runs like this:

  1. Open the sign-in logs in the Microsoft Entra admin center and add the Authentication Protocol filter set to Device code.
  2. Export the results and group them by user, application and device. Look at interactive and non-interactive sign-ins, because token refreshes after a device code sign-in appear in the non-interactive view.
  3. To check device registration use specifically, Microsoft documents filtering by the Device Registration Service client ID in the Resource ID filter and then selecting Device code in the Authentication Protocol filter.
  4. For each user and application pair, find an owner and ask a simple question: does this need device code flow, or is it habit?

Expect three kinds of result. First, genuine input-constrained devices such as meeting room hardware or signage. Second, administrators and developers who use command-line tools that offer a device code sign-in option because it is convenient over a remote session. Third, sign-ins nobody recognises, which should go straight to your incident process rather than into an exception list. Our Device Code Phishing Guide covers how to investigate that third group.

For the second group, the usual fix is to switch the tool to an interactive browser sign-in or, for automation, to move it off user sign-in entirely. Microsoft notes in the same procedure that if your organisation uses service accounts in scripts or code, you should replace them with managed identities. That moves the workload into the non-human identity estate where it belongs, and you can then govern it with Conditional Access for Workload Identities.

Step 2: Build the block policy in report-only mode

Microsoft's documented procedure for organisations that do not use device code flow is as follows. The wording below follows the current admin center labels.

  1. Sign in to the Microsoft Entra admin center as at least a Conditional Access Administrator.
  2. Browse to Entra ID > Conditional Access > Policies.
  3. Select New policy and give it a clear name, for example a name that states the flow, the action and the scope.
  4. Under Assignments, select Users or workload identities. Under Include, select All users. Under Exclude, select Users and groups and choose your emergency access or break-glass accounts and any other necessary users.
  5. Under Target resources > Resources (formerly cloud apps) > Include, select All resources (formerly 'All cloud apps').
  6. Under Conditions > Authentication Flows, set Configure to Yes, select Device code flow, then select Done.
  7. Under Access controls > Grant, select Block access, then Select.
  8. Set Enable policy to Report-only and select Create.

Leave the policy in report-only long enough to cover your normal business cycle, including month-end processes, scheduled maintenance windows and any quarterly tasks run by administrators. Report-only results tell you which sign-ins would have been blocked without blocking them, which is exactly the evidence you need to agree exceptions with application owners.

Do not add a second grant control or an MFA requirement to this policy. Device code phishing works because the victim completes MFA themselves, so a policy that only requires MFA for device code sign-ins does not stop the attack. The control that matters is Block access.

Step 3: Design the exceptions

Microsoft's guidance is to get as close as possible to a unilateral block and only allow device code flow in well documented and secured use cases, like legacy tooling that can't be updated. There are three kinds of exception to plan for.

Emergency access accounts

Microsoft recommends excluding emergency access or break-glass accounts from Conditional Access policies to prevent lockout due to policy misconfiguration. Exclude them by group, alert on every sign-in they make, and audit the exclusion list regularly, which Microsoft also calls out in the procedure. Our guide on How to set up and monitor break-glass accounts in Entra ID with passkeys and alerts covers the monitoring side.

The Device Registration Service

Microsoft documents that, starting early September 2024, it began enforcing authentication flows policies on the Device Registration Service. This applies only to policies that target all resources. If your organisation uses device code flow for device registration and your authentication flows policy targets all resources, you need to exempt the Device Registration Service from the policy scope to avoid impact.

The documented path is Target Resources > Exclude > Select excluded cloud apps > Device Registration Service. If you manage policies through the API, exclude client ID 01cb2876-7ebd-4aa4-9cc9-d28bd4d359a9. Only make this exclusion if your Step 1 audit showed device code sign-ins to that resource. An exclusion you do not need is attack surface you do not need.

Genuine input-constrained devices

Microsoft's own example is a tenant that uses device code flow for Android-based conference room devices, where the recommended pattern is to block device code flow everywhere except for Android devices in a specific network location. That shape is the right model for any device exception:

  • A dedicated group containing only the accounts that sign in to those devices, not the people who use the meeting rooms.
  • Device conditions that match the platform in use, so the exception does not apply to laptops and phones.
  • A named network location covering the sites where the devices sit, so a code entered from anywhere else is still blocked.
  • A named owner, a business justification, and a review date recorded alongside the policy.

Build this as a second, narrower policy, or as an exclusion in the main policy, depending on how your tenant structures Conditional Access. Either way, the room device accounts are shared credentials in practice, so treat them with the same rigour as any other non-human identity: inventory, ownership and rotation. The Conditional Access Guide covers policy layout patterns in more depth.

Step 4: Switch the policy on

Once report-only results show only the activity you expect, and every legitimate use is either remediated or covered by a documented exception, Microsoft's instruction is to move the Enable policy toggle from Report-only to On.

Before you do, brief your service desk. Users who previously signed in to a tool with a device code will now see a block, and some sessions may be signed out because of protocol tracking, described next. Give the service desk the policy name, the exception request route, and a short script explaining that the block is intentional.

Pick a change window that is not your busiest day, keep a Conditional Access Administrator on hand for the first few hours, and agree a rollback threshold in advance. Rolling back means returning the policy to report-only, not deleting it.

How protocol tracking changes what gets blocked

This is the part that surprises most teams. Microsoft explains that to enforce authentication flows policies accurately it uses protocol tracking. A session that used device code flow or authentication transfer is marked as protocol tracked, and protocol tracked sessions are subject to policy enforcement if a policy exists. The tracking state persists through subsequent token refreshes, so requests that are not themselves device code flow can still be blocked by an authentication flows policy.

Microsoft gives a worked example. Configure a policy that blocks device code flow everywhere except SharePoint. A user signs in to SharePoint with device code flow, which is allowed, and the session is now protocol tracked. If the user then tries to reach Exchange in the same session using any authentication flow, they are blocked because of the protocol tracked state.

Two consequences follow for exception design:

  • Exceptions scoped to a single application do not give users broad access from that session. That is good for security, but it means a device that signs in with device code to one allowed resource cannot quietly pivot to others.
  • Microsoft notes that blocks due to protocol tracked sessions are expected behaviour and can include not being able to access certain resources or complete device sign out. There is no recommended remediation while the policy is enabled. If the policy is set to disabled or report-only, you may need to obtain a fresh token in order to use the device again.

Troubleshooting unexpected blocks

Microsoft documents a troubleshooting sequence for blocks you did not expect:

  1. Go to the sign-in logs, select the blocked sign-in, and open the Conditional Access tab in Activity details: sign-ins.
  2. If an authentication flows policy was enforced, select it to see which flow matched.
  3. If device code flow matched but was not the flow the user actually performed, check the Original transfer method property in the Basic info pane. Microsoft added this property to show the protocol tracking state of the request; for a session in which device code flow was performed previously, it is set to Device code flow.
  4. For policies that apply to all applications, search for error AADSTS530036, which Microsoft documents as a refresh token being invalid due to authentication flow checks by Conditional Access, where the token will never be usable and should be deleted.

When a user reports a block, the Original transfer method value is the fastest way to tell a genuine new device code attempt from a protocol tracked session left over from an earlier sign-in. A genuine new attempt from an account that has no reason to use the flow is worth a security review, because it may be a phishing attempt that the policy has just stopped.

Keeping the policy healthy

A block policy decays if nobody looks at it. Build these into routine operations:

  • Exception reviews: review every excluded group on a fixed schedule. Remove members who have left, and retire device exceptions when hardware is replaced.
  • Sign-in monitoring: keep a saved view or detection on successful sign-ins with authentication protocol set to device code. In a tenant with a tenant-wide block, every success should map to a documented exception.
  • Change control: treat edits to this policy as high-risk changes. Removing the authentication flows condition or switching the policy to report-only reopens the attack path for the whole tenant.
  • Policy companions: device code blocking closes one token-theft path. Pair it with phishing-resistant authentication for administrators, covered in the Entra Authentication Strengths Guide.

Common failure patterns

  • Requiring MFA instead of blocking: the victim completes MFA during device code phishing, so an MFA requirement on the flow does not stop it.
  • Skipping report-only: going straight to On without an audit breaks room devices and admin tooling, and the resulting pressure leads to broad exceptions.
  • Exceptions by user, not by device and location: excluding a person rather than a room device account in a named location leaves that person fully phishable.
  • Forgetting the Device Registration Service: an all-resources policy without the documented exclusion can disrupt device registration where device code flow is used for it.
  • Misreading protocol tracking blocks as bugs: teams disable the policy to fix a protocol tracked block that Microsoft documents as expected behaviour.
  • Leaving scripts on user accounts: automation that signs in with device code under a user account becomes a permanent exception instead of a managed identity.
  • Unowned exclusion groups: groups without an owner or review date grow quietly until the block covers only part of the tenant.

Practitioner checklist

  • Confirm emergency access accounts exist, are excluded by group, and alert on every sign-in.
  • Run a sign-in log audit with the Authentication Protocol filter set to Device code, covering interactive and non-interactive sign-ins.
  • Check Device Registration Service use with the Resource ID filter before deciding on that exclusion.
  • Move scripts and automation off user device code sign-in and onto managed identities.
  • Create the block policy for All users and All resources with Device code flow selected and Block access as the grant.
  • Run it in Report-only across a full business cycle and review every would-be block.
  • Scope each device exception by group, device platform and named network location, with an owner and review date.
  • Brief the service desk, then switch the policy to On in a planned change window.
  • Teach responders to read Original transfer method and recognise AADSTS530036.
  • Alert on successful device code sign-ins that do not match a documented exception.
  • Decide separately whether to block Authentication transfer, in its own policy.

Standards and references

Related NHI Mgmt Group resources: Device Code Phishing Guide · Storm-2372 (device code phishing) threat actor profile · Conditional Access Guide · Entra ID Security Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.