Guide Guides

Device code phishing in Microsoft 365: how to spot it, find it in your logs and block it

In device code phishing the victim never types a password into a fake site. They enter a short code on Microsoft's genuine sign-in page, pass multifactor authentication - and the tokens for their account go to the attacker. Microsoft recommends blocking this sign-in method wherever possible. Here is how to find out who uses it in your organisation, how to switch it off with Conditional Access, and what to do if someone has already entered a code.

Kyberkit editorial team · · reading time 7 minutes · For admins and analysts

Guide: Device code phishing in Microsoft 365

Key points

  • Device code flow is a legitimate sign-in method for devices without a keyboard (TVs, meeting rooms, CLI tools). The attacker generates the code and gets the victim to enter it on Microsoft's real page.
  • Passwords and MFA do not help: the victim authenticates themselves and the attacker receives the access and refresh tokens. Microsoft documented such campaigns by Storm-2372 (since August 2024, governments, NGOs, energy).
  • Microsoft recommends blocking device code flow wherever possible: Entra ID → Conditional Access → Authentication flows condition → Device code flow → Block access. Start in Report-only.
  • Find usage in sign-in logs with the Authentication protocol = Device code filter. If you suspect compromise, revoke sessions (revokeSignInSessions) and review newly registered devices.

How device code phishing works

Device code sign-in (device code flow, the OAuth 2.0 device authorization grant, RFC 8628) exists for devices that are awkward to type on: smart TVs, printers, meeting-room systems and command-line tools. The device asks Microsoft for a short code and tells you to enter it on another device at microsoft.com/devicelogin. Once you sign in there, the device receives tokens for your account. Microsoft's documentation gives the user 15 minutes to enter the code.

The attack turns this around. The "device" is the attacker's machine: they generate the code themselves and send it to the victim wrapped in something that looks routine - a Teams meeting invitation, a "verification" step for a shared document, an invite to a chat. The victim opens Microsoft's real page, enters the code, signs in including MFA, and the attacker receives an access token and a refresh token. They never learn the password and don't need it.

Device code phishing flow as described by Microsoft Threat Intelligence1. Attacker requests a device code from Microsoft; 2. Sends the victim an invite or message containing the code; 3. Victim enters the code on Microsoft's real page and completes MFA; 4. Attacker receives access and refresh tokens; 5. Reads mail and data via Microsoft Graph1Attacker requests a device code fromMicrosoft2Sends the victim an invite or messagecontaining the code3Victim enters the code on Microsoft'sreal page and completes MFA4Attacker receives access and refreshtokens5Reads mail and data via MicrosoftGraph
Device code phishing, simplified, based on Microsoft's description of the Storm-2372 campaign

That is why the usual advice - "check the address bar" and "turn on MFA" - fails here. The address is genuine and the victim completes MFA themselves.

Why this is not a theoretical threat

On 13 February 2025 Microsoft Threat Intelligence described a campaign by a group it tracks as Storm-2372. According to Microsoft it has been active since August 2024 and targets government, NGOs, IT services, defence, telecoms, health, higher education and energy across Europe, North America, Africa and the Middle East. The operators first posed as a prominent person over WhatsApp, Signal or Teams, built rapport, and then sent an online meeting invitation containing the code.

After taking over an account, Microsoft says the actor:

  • sent further phishing to colleagues from the compromised mailbox,
  • searched mail through Microsoft Graph for words such as password, admin, credentials and secret, and exfiltrated what it found,
  • later switched to the Microsoft Authentication Broker client ID, registered its own device in Entra ID and obtained a Primary Refresh Token (PRT) to keep access for longer.

On 17 November 2026 Microsoft applied the same technique to AI coding agents - see our report Device code phishing can hand an attacker your AI coding agent.

Step 1: Find out who uses device code flow

Before you block anything, check whether anyone relies on it (meeting rooms, Azure CLI, PowerShell modules, legacy tools).

In the portal: Microsoft Entra admin center → Entra ID → Monitoring & health → Sign-in logs. Add the Authentication protocol filter and choose Device code. Review both interactive and non-interactive sign-ins.

In Log Analytics / Microsoft Sentinel (if you stream sign-in logs there), a query like this gives a similar overview:

SigninLogs
| where TimeGenerated > ago(30d)
| where AuthenticationProtocol == "deviceCode"
| summarize Count = count(), LastSeen = max(TimeGenerated) by UserPrincipalName, AppDisplayName, IPAddress
| sort by Count desc

What to look for: users who have never used device code before; sign-ins from IP addresses or countries the person doesn't normally work from; apps nobody in your organisation uses. In its Defender XDR hunting query Microsoft also looks for a click on a device login URL followed shortly, for the same user, by sign-in error 50199 and then a successful sign-in - the moment the victim is entering the code.

A quicker route is the policy from step 2 in Report-only mode: it blocks nothing and simply records who it would have blocked.

Step 2: Block device code flow with Conditional Access

Microsoft recommends getting as close as possible to a complete block and allowing device code flow only for documented, secured use cases. The steps, per the documentation:

  1. Sign in to the Microsoft Entra admin center as at least a Conditional Access Administrator.
  2. Go to Entra ID → Conditional Access → Policies → New policy.
  3. Users or workload identities → Include: All users. Exclude: emergency access (break-glass) accounts and any other essential accounts. Review the exclusion list regularly.
  4. Target resources → Resources → Include: All resources.
  5. Conditions → Authentication Flows → Configure: Yes → tick Device code flow → Done.
  6. Access controls → Grant → Block access.
  7. Set Enable policy to Report-only and create the policy.
  8. Once you have checked the impact (report-only or policy impact), switch it to On.

Two things people forget:

  • Device registration. Since September 2024 Microsoft enforces authentication flows policies on the Device Registration Service when the policy targets All resources. If you use device code to register devices, exclude the service (Target resources → Exclude → Device Registration Service, client ID 01cb2876-7ebd-4aa4-9cc9-d28bd4d359a9).
  • Keep exceptions narrow. Don't allow Android meeting-room devices for the whole tenant. Microsoft's own example: block everywhere except Android devices in a specific network location.

The same condition also covers Authentication transfer (moving a sign-in from desktop to mobile via a QR code in Outlook). If you don't want people signing in this way on personal phones, block it the same way.

Licensing: Conditional Access requires Microsoft Entra ID P1 (Microsoft 365 Business Premium includes it). Without it you have security defaults, user awareness and the log monitoring from step 1.

What may break when you switch it on

For sessions that started with a device code, Microsoft uses protocol tracking: the session remembers it began via device code, and the policy applies to it on later token refreshes - even if you then sign in another way. After enabling the policy, older tools or an entire device may get signed out.

You can confirm this in the logs: on the blocked sign-in, Activity details shows the Original transfer method property set to Device code flow, or error AADSTS530036. Microsoft says this is expected; signing in again the normal way resolves it.

What to tell your users

A short message for all staff:

  • Only enter a device code when you started the sign-in yourself on a device in front of you (the meeting-room TV, a tool in your terminal).
  • A meeting invitation, shared document or chat message never needs you to copy a code anywhere. If someone asks you to, it's a scam - even if the link goes to Microsoft's real site.
  • If you have already entered a code, report it to IT immediately. Changing your password is not enough; the attacker holds tokens.

If you received a suspicious invitation email, you can examine its headers with our Email Header Analyzer - the data stays in your browser.

If someone has already entered a code

  1. Revoke the user's sessions - in the Entra portal (user → Revoke sessions), via Graph POST /users/{id}/revokeSignInSessions, or in PowerShell with Revoke-MgUserSignInSession -UserId <UPN>. The documentation notes revocation can take a few minutes.
  2. Review devices registered to the user in recent days. Microsoft says Storm-2372 registered its own device to obtain a PRT - disable and delete any device you don't recognise.
  3. Check the mailbox: forwarding and deletion rules, sent items (phishing to colleagues) and Microsoft Graph access in the audit log.
  4. Block device code flow as in step 2 if you haven't already.
  5. Follow your incident response plan and your national CERT's reporting process; the NCSC's incident management guidance is a good checklist.

Updates

  • 18 Nov 2026: Published. Steps verified against Microsoft Learn documentation (Conditional Access, device code flow, revokeSignInSessions) and Microsoft Threat Intelligence's Storm-2372 report.

FAQ

Does multifactor authentication protect against device code phishing?

No. The victim enters the code on Microsoft's real page and completes MFA themselves. The tokens, however, go to the device that generated the code - the attacker's. That is why Microsoft recommends blocking device code flow with Conditional Access.

Do I need a paid licence to block device code flow?

Conditional Access requires a Microsoft Entra ID P1 licence; Microsoft 365 Business Premium includes it too. Without it you are left with security defaults, user awareness and monitoring sign-in logs.

What if we genuinely need device code flow, for example for meeting rooms?

Microsoft recommends allowing it only for well-documented cases. You can narrow the exception in the policy, for example to specific devices in a specific network location, and block it everywhere else.

Why did an app that doesn't use device code stop signing in after I enabled the policy?

According to Microsoft, a session that once started with a device code is 'protocol tracked', and the policy applies to it on later token refreshes as well. In the logs you will see the Original transfer method property and error AADSTS530036. Signing in again the normal way fixes it.

Sources

  1. Microsoft Learn - Block authentication flows with Conditional Access policy
  2. Microsoft Learn - Authentication flows as a condition in Conditional Access policy
  3. Microsoft Learn - OAuth 2.0 device authorization grant
  4. Microsoft Threat Intelligence - Storm-2372 conducts device code phishing campaign (13 Feb 2025, updated 31 Jul 2026)
  5. Microsoft Learn - user: revokeSignInSessions (Microsoft Graph)
  6. Microsoft Learn - signIn resource type: authenticationProtocol, originalTransferMethod
  7. Microsoft Learn - Conditional Access overview: license requirements
  8. Microsoft Learn - Azure Monitor Logs reference: SigninLogs (AuthenticationProtocol column)
  9. NCSC UK - Phishing attacks: defending your organisation

Spotted a mistake? Let us know and we will correct it openly.