OAuth 2.0 Device Code Flow for Input-Constrained Devices
Learn how the Device Code grant (RFC 8628) enables OAuth 2.0 authentication on smart TVs, CLI tools, and IoT devices with limited input capabilities.
Detailed Explanation
Device Authorization Grant (RFC 8628)
The Device Code flow enables OAuth 2.0 authentication on devices that lack a convenient text-input mechanism — smart TVs, game consoles, printers, CLI tools, and IoT devices. Instead of entering credentials on the device itself, the user completes authentication on a separate device with a full browser.
How It Works
Device Authorization Request: The device sends a POST to
/device/codewith itsclient_idand desiredscope.Device Code Response: The server returns a
device_code, a short human-readableuser_code, averification_uri, and a pollinginterval.User Instruction: The device displays the
user_codeandverification_urito the user (e.g., "Go to https://example.com/device and enter code: WDJB-MJHT").User Authorization: The user visits the URL on their phone or laptop, enters the code, logs in, and grants consent.
Polling: Meanwhile, the device polls the
/tokenendpoint at the specified interval usinggrant_type=urn:ietf:params:oauth:grant-type:device_code.Access Token: Once the user completes authorization, the next poll returns an access token. Before that, the server responds with
authorization_pendingorslow_downerrors.
Polling Responses
| Error | Meaning |
|---|---|
authorization_pending |
User hasn't completed authorization yet — keep polling |
slow_down |
Polling too fast — increase interval by 5 seconds |
expired_token |
Device code has expired — start over |
access_denied |
User denied the request |
Security Considerations
- Use high-entropy user codes to prevent brute-force guessing
- Implement rate limiting on the polling endpoint
- Set reasonable expiration for device codes (10-15 minutes)
- Display the complete verification URI clearly
Use Case
A smart TV streaming application (like Netflix or YouTube) that needs the user to log in. The TV displays a short code and a URL. The user opens the URL on their phone, enters the code, and logs in. The TV automatically receives an access token once authorization is complete.