OAuth Device Authorization Grant: approve sign-in on a phone for a TV
Learn how the OAuth Device Authorization Grant works on input-constrained devices, how polling should behave, and how to avoid cross-device consent phishing.
OAuth Device Authorization Grant: approve sign-in on a phone for a TV
The OAuth 2.0 Device Authorization Grant is a flow for TVs, printers, kiosks, and other devices with no browser or limited input. The device starts a sign-in and authorization request, and the user completes it on a separate phone or computer. The device displays a short user code and an authorization-server address; the user opens that address in a trusted browser, enters the code, and reviews the request. This is convenient, but the user must trust the request across two devices and should watch for fake approval requests.
The standard flow
**The device starts an authorization request.** In response to a user action, the OAuth client sends a request to the authorization server's device authorization endpoint.
**The server returns codes and timing information.** An RFC 8628 response must include `device_code`, `user_code`, `verification_uri`, and `expires_in`, the codes' validity period in seconds. The polling interval `interval` and a complete URL, `verification_uri_complete`, which can be used for QR transfer, are optional. If `interval` is absent, the client must use a default of 5 seconds.
**The user reviews the request on a second device.** In a browser on a phone or computer, the user opens the official `verification_uri` shown by the device, enters the `user_code`, signs in, and approves or denies the request.
**The original device checks the token endpoint.** The client sends the `device_code` at the interval set by the server to check whether approval is complete. If approved, it receives an access token and possibly other tokens. If the request is denied or the code expires, the client ends the flow.
This flow is not meant to replace the standard OAuth browser flow on a smartphone or ordinary desktop browser where the user can readily interact with the browser and enter information. It is intended for a constrained device that starts the request and a separate device with a suitable browser that completes it.
Handling codes and polling safely
The server must rate-limit attempts to guess a `user_code`. The code may be short to make it easy to enter, which makes brute-force attempts more practical.
RFC 8628 recommends creating an authorization request after a user starts the process, rather than automatically creating new requests when an app starts or immediately after a failure. `authorization_pending` means approval is still pending. Before each poll, the client must wait for `interval` seconds, or 5 seconds if no interval was supplied. When the server returns `slow_down`, the client must add 5 seconds to the current polling interval and keep that longer interval for subsequent polls.
If the server returns another error, such as `access_denied` or `expired_token`, the client stops polling as specified by the RFC. If an expired request must be tried again, tell the user to start a new sign-in. After a connection timeout, the client must reduce its request frequency; the RFC recommends an approach such as exponential backoff.
Set validity periods for `device_code` and `user_code`, and require the user to start a new request after expiry. RFC 8628 says to keep codes short-lived when possible so they are harder to exploit for phishing.
Show the device type and request context on the approval screen, and help the user confirm that the request comes from a device they actually control. RFC 8628 especially recommends checking that the physical device the user intends to authorize matches the displayed code when a QR code transfers the code automatically.
Cross-device consent phishing
An attacker can start an OAuth authorization on a device they control, then persuade a victim to enter the code on the official authorization page by claiming it is for “account verification” or “support.” If the victim approves, access may be granted to the attacker's device. RFC 10027 describes this as cross-device consent phishing and notes that the request context is not technically authenticated across the two devices, so the user must judge where the request came from. The attack can succeed without stealing a password, so MFA alone does not establish that the request is safe.
If users did not start a request directly on the TV or app they intend to sign in to, they should not enter a code or scan a QR code. They should read the app or device name and the purpose shown on the approval screen, and deny unfamiliar devices or requests they do not understand. Service operators should clearly say that a device is requesting approval and, where possible, let users compare the information on the device screen with what appears on the approval screen.
References
[RFC 8628: OAuth 2.0 Device Authorization Grant](https://www.rfc-editor.org/rfc/rfc8628.html)
[RFC 10027: Best Current Practice for Security of Cross-Device Flows](https://www.rfc-editor.org/rfc/rfc10027.html)