Device Code Flow (OAuth 2.0 Device Authorization Grant)
Device Code Flow (OAuth 2.0 Device Authorization Grant) 是什么?
Device Code Flow (OAuth 2.0 Device Authorization Grant)An OAuth 2.0 grant (RFC 8628) where an input-constrained device (smart TV, CLI, IoT device) shows the user a code and a verification URL to authenticate on a second device — convenient for CLIs but a documented phishing vector.
The OAuth 2.0 Device Authorization Grant, specified in RFC 8628 and colloquially called the device code flow, lets a client without a usable browser (smart TVs, CLIs, kiosks, IoT devices) obtain user-delegated tokens by asking the user to authenticate on a separate device. The client requests a `device_code` and a short `user_code` from the IdP and displays the user_code plus a verification URL (e.g. `https://microsoft.com/devicelogin`); the user opens that URL on their phone or laptop, signs in, types the user_code, and consents. The IdP issues tokens to the original device. The flow is the basis for `gh auth login`, `az login --use-device-code`, Apple TV sign-in, Roku and Google TV pairing, and many CLI tools. It is also a documented phishing vector: an attacker can initiate a device code flow against a target tenant and send the user_code in a phishing message, tricking the victim into authenticating on a legitimate IdP page that issues tokens to the attacker (see Storm-2372). Defensive controls include Conditional Access policies that restrict the device code flow to specific apps or user groups, throttling, and user education.
● 示例
- 01
`gh auth login` prints a short user code and a URL; the user signs in on a laptop, enters the code, and the CLI receives tokens.
- 02
An Entra ID Conditional Access policy disables the device-code flow tenant-wide except for a tightly scoped CLI-user group.
● 常见问题
Device Code Flow (OAuth 2.0 Device Authorization Grant) 是什么?
An OAuth 2.0 grant (RFC 8628) where an input-constrained device (smart TV, CLI, IoT device) shows the user a code and a verification URL to authenticate on a second device — convenient for CLIs but a documented phishing vector. 它属于网络安全的 身份与访问 分类。
Device Code Flow (OAuth 2.0 Device Authorization Grant) 是什么意思?
An OAuth 2.0 grant (RFC 8628) where an input-constrained device (smart TV, CLI, IoT device) shows the user a code and a verification URL to authenticate on a second device — convenient for CLIs but a documented phishing vector.
Device Code Flow (OAuth 2.0 Device Authorization Grant) 是如何工作的?
The OAuth 2.0 Device Authorization Grant, specified in RFC 8628 and colloquially called the device code flow, lets a client without a usable browser (smart TVs, CLIs, kiosks, IoT devices) obtain user-delegated tokens by asking the user to authenticate on a separate device. The client requests a `device_code` and a short `user_code` from the IdP and displays the user_code plus a verification URL (e.g. `https://microsoft.com/devicelogin`); the user opens that URL on their phone or laptop, signs in, types the user_code, and consents. The IdP issues tokens to the original device. The flow is the basis for `gh auth login`, `az login --use-device-code`, Apple TV sign-in, Roku and Google TV pairing, and many CLI tools. It is also a documented phishing vector: an attacker can initiate a device code flow against a target tenant and send the user_code in a phishing message, tricking the victim into authenticating on a legitimate IdP page that issues tokens to the attacker (see Storm-2372). Defensive controls include Conditional Access policies that restrict the device code flow to specific apps or user groups, throttling, and user education.
如何防御 Device Code Flow (OAuth 2.0 Device Authorization Grant)?
针对 Device Code Flow (OAuth 2.0 Device Authorization Grant) 的防御通常结合技术控制与运营实践,详见上方完整定义。
Device Code Flow (OAuth 2.0 Device Authorization Grant) 还有哪些其他名称?
常见的别称包括: RFC 8628, OAuth 2.0 Device Authorization Grant。
● 相关术语
- identity-access№ 839
OAuth 2.0
开放的授权框架,允许资源所有者在不共享凭据的情况下,授予第三方应用对 API 的有限范围访问。
- attacks№ 341
Device Code Phishing
An identity attack that abuses the OAuth 2.0 device authorization grant: the attacker starts a device-code flow and lures the victim into typing the resulting code on a legitimate login page, granting the attacker tokens for the victim's account.
- identity-access№ 852
OpenID Connect (OIDC)
构建在 OAuth 2.0 之上的身份层,允许客户端通过签名的 ID 令牌验证用户身份并获取基本资料。
- identity-access№ 090
授权
在身份认证完成后,决定该身份对哪些资源、可以执行哪些操作以及在何种条件下被允许的过程。
- identity-access№ 1162
单点登录 (SSO)
一种认证方式,用户在可信的身份提供方完成一次登录后,即可访问多个应用而无需再次输入凭据。
- identity-access№ 928
PKCE (Proof Key for Code Exchange)
An OAuth 2.0 extension (RFC 7636) that binds an authorization-code redemption to a one-time secret created by the client, neutralizing authorization-code interception attacks on public and confidential clients alike.