Query Details
id: e0f6a8b9-c4d5-7e1f-2a3b-4c5d6e7f8a9b
name: Device Code Flow Authentication Abuse
version: 1.0.0
kind: Scheduled
description: |
Detects non-interactive sign-ins using device code flow authentication protocol.
Device code flow is commonly abused in phishing attacks where a user is tricked into
entering a device code on a legitimate Microsoft page. The attacker redeems the code
and obtains a long-lived refresh token that enables silent authentication indefinitely.
Any use of device code flow should be reviewed unless explicitly expected.
MITRE ATT&CK: T1528 (Steal Application Access Token), T1566 (Phishing)
severity: High
requiredDataConnectors:
- connectorId: AzureActiveDirectory
dataTypes:
- AADNonInteractiveUserSignInLogs
queryFrequency: 1h
queryPeriod: 1h
triggerOperator: gt
triggerThreshold: 0
tactics:
- CredentialAccess
- InitialAccess
relevantTechniques:
- T1528
- T1566
query: |
AADNonInteractiveUserSignInLogs
| where TimeGenerated > ago(1h)
| where AuthenticationProtocol == "deviceCode"
or ClientAppUsed has_any ("device code", "device_code", "Device Code")
| summarize
Count = count(),
IPs = make_set(IPAddress),
Countries = make_set(Location),
Apps = make_set(AppDisplayName),
FirstSeen = min(TimeGenerated),
LastSeen = max(TimeGenerated)
by UserPrincipalName
| extend IPAddress = tostring(IPs[0])
| order by Count desc
entityMappings:
- entityType: Account
fieldMappings:
- identifier: FullName
columnName: UserPrincipalName
- entityType: IP
fieldMappings:
- identifier: Address
columnName: IPAddress
customDetails:
SignInCount: Count
Countries: Countries
Apps: Apps
alertDetailsOverride:
alertDisplayNameFormat: "Device Code Flow Detected for {{UserPrincipalName}}"
alertDescriptionFormat: "User {{UserPrincipalName}} had {{Count}} device code flow non-interactive sign-ins. This protocol is abused in phishing attacks to obtain long-lived refresh tokens."
incidentConfiguration:
createIncident: true
groupingConfiguration:
enabled: true
reopenClosedIncident: false
lookbackDuration: PT5H
matchingMethod: AnyAlert
groupByEntities:
- Account
groupByAlertDetails: []
groupByCustomDetails: []
This query is designed to detect suspicious sign-ins using the "device code flow" authentication protocol, which is often exploited in phishing attacks. Here's a simple breakdown:
Overall, this query helps security teams monitor and respond to potential phishing attacks that exploit the device code flow authentication method.

David Alonso
Released: May 29, 2026
Tables
Keywords
Operators