RFC 8628 — OAuth 2.0 Device Authorization Grant
Implemented (apiauth.MountDeviceFlow)
Source: docs/oauth/RFC_8628.md
RFC 8628 — OAuth 2.0 Device Authorization Grant ¶
Status: Standards Track
Published: 2019-08
L-tier / T-tier: L4 · T5 (alternative to T2–T4 redirect flow)
OneAuth coverage: Implemented (apiauth.MountDeviceFlow)
See also:RFC_6749.md·LANDSCAPE.md
In one sentence ¶
The device flow lets input-constrained clients (smart TVs, CLIs, IoT
gadgets) get OAuth tokens without ever running a browser themselves — they
display a short code; the user authorizes on a phone or laptop; the device
polls until done.
What problem does it solve? ¶
| Without 8628 | With 8628 |
|---|---|
| Smart TVs and CLIs use cumbersome on-device keyboards to type passwords / paste tokens — bad UX, often insecure | User authorizes on a real browser; device just polls |
| Headless tooling (CI/CD bootstrappers, CLI tools) prompts for credentials in plain text — leaks into history | One-time short code; no credential typed at the device |
| IoT devices share a single embedded credential across all units — leak risk multiplies | Each device gets its own auth flow without per-device pre-provisioning |
The device flow is the correct answer to “OAuth on a TV.” Before 8628,
TVs typically displayed a short URL and asked you to type a long
device-specific token. After 8628, you get a short URL + a 8-character code
that expires in minutes.
Relatable example ¶
Every time you’ve added a streaming service to a smart TV:
- TV shows: “Go to
https://disney.com/beginand enter the codeWDJK-XQPL.” - You go to that URL on your phone, log into Disney+, type the code.
- Behind the scenes, the TV has been polling Disney+’s
/tokenendpoint
every few seconds: “isdevice_code=abc-secret-...authorized yet?” - As soon as you finish on your phone, the TV’s next poll returns an
access token; the TV switches from “waiting” to “logged in.”
GitHub’s gh auth login CLI uses exactly this flow. Spotify Connect, Apple
TV third-party apps, Roku — same pattern everywhere.
Key concepts ¶
- Two endpoints:
POST /device/authorize(where the device kicks off
the flow) and the existingPOST /token(where the device polls).
Plus theverification_uri(where the user goes in a browser) — that
one is just a regular web page on the AS. - Two correlated codes:
device_code(long, kept by the device,
polled with) anduser_code(short, displayed to the user — 8 chars
typical:ABCD-EFGH). verification_urivsverification_uri_complete. The complete
form embeds the user code (?user_code=ABCD-EFGH) so a QR code can
skip the typing step entirely.- Polling has rules. Device polls with grant type
urn:ietf:params:oauth:grant-type:device_code. AS responds with one of:{access_token: ..., ...}— doneauthorization_pending— still waiting; keep pollingslow_down— you’re polling too fast; back offaccess_denied— user said noexpired_token— give up; restart the flow
- Expiry is short.
expires_inis typically 300–900 seconds (5–15
minutes). Codes shouldn’t sit valid for hours — the attack surface
for shoulder-surfed user codes is real.
Wire example ¶
Step 1 — device asks for codes:
POST /device/authorize HTTP/1.1
Host: as.example.com
Content-Type: application/x-www-form-urlencoded
client_id=tv-public-client&scope=read+watch
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"device_code": "GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS",
"user_code": "WDJK-XQPL",
"verification_uri": "https://as.example.com/device",
"verification_uri_complete": "https://as.example.com/device?user_code=WDJK-XQPL",
"expires_in": 900,
"interval": 5
}
The TV displays verification_uri + user_code, or a QR encoding
verification_uri_complete.
Step 2 — user authorizes on phone.
User browses to https://as.example.com/device, types WDJK-XQPL, logs
in, consents. AS marks device_code as authorized.
Step 3 — TV polls /token until ready:
POST /api/token HTTP/1.1
Host: as.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=urn:ietf:params:oauth:grant-type:device_code
&device_code=GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS
&client_id=tv-public-client
Initially: {"error": "authorization_pending"}. Then, eventually:
HTTP/1.1 200 OK
{
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
"scope": "read watch"
}
Where it lands on the OAuth abstraction ¶
- L4 grant types. Device flow plugs into the
/tokenslot at T5,
replacing the browser-driven T2-T4 leg. - T5 (alternative to T2-T4). No browser at the client; the user’s
separate browser session is the “T2-T4” leg, decoupled in time and
device. - Sibling solution at the same layer: OIDC CIBA for cases where the
user doesn’t have a browser at all (push notifications, voice
assistants).
OAuth 2.0 status ¶
Published 2019. Part of the OAuth 2.0 family. Widely deployed: GitHub,
Auth0, Google (Google calls it “OAuth 2.0 for limited input devices”),
Microsoft, Apple TV’s auth path.
The 2.0 status is implemented mostly everywhere a smart TV vendor or CLI
maker needs it. Less common in browser-based consumer flows because
they don’t need it.
OAuth 2.1 status ¶
Not changed by 2.1. Device flow is included in 2.1’s grant lineup
unchanged. The polling discipline (interval, slow_down) is unchanged.
OneAuth status ¶
| 8628 surface | Status | Where (grep-verified) | Notes |
|---|---|---|---|
POST /device/authorize endpoint |
Implemented | apiauth/device_auth_grant.go DeviceAuthorizationHandler.ServeHTTP; mounted by apiauth.MountDeviceFlow (apiauth/device_flow_mount.go) |
RFC 8628 §3.1–3.2 |
device_code, user_code, verification_uri (§3.2) |
Implemented | Returned by DeviceAuthorizationHandler |
— |
verification_uri_complete (§3.3.1) |
Implemented | DeviceFlowMountConfig.VerificationURICompleteTemplate / DeviceAuthorizationHandler.VerificationURICompleteTemplate substitutes the user code into a template URL |
Used for QR-code shortcuts |
interval polling hint (§3.5) |
Implemented | DeviceFlowMountConfig.Interval; zero uses DefaultDeviceAuthorizationInterval (5s) |
— |
expires_in (§3.2) |
Implemented | DeviceFlowMountConfig.Expiry; zero uses DefaultDeviceAuthorizationExpiry (15 minutes) |
Configurable |
| Registered scope at device authorization | Implemented | DeviceAuthorizationHandler.ServeHTTP calls grantScopes (apiauth/client_policy.go) |
A scope outside AppRegistration.Scope gets 400 invalid_scope. With no scope asked for, the registered scope is granted (0.1.49). |
| User-code brute-force limit (§5.1) | Implemented | DeviceFlowMountConfig.UserCodeRateLimiter; nil uses DefaultUserCodeRateLimiter |
MountDeviceFlow always installs a limiter on POST /device, keyed by client address through core.ClientIP and TrustedProxies (0.1.44). |
| Framing and caching | Implemented | httpauth.DenyFraming on the DeviceVerificationHandler pages; noStore in writeOAuthError |
The code entry, consent and done pages refuse framing. The device authorization response and every device error carry Cache-Control: no-store (0.1.44). |
POST /token with grant_type=...:device_code |
Implemented | TokenEndpointHandler.dispatchDeviceCode (apiauth/token_endpoint.go) dispatches to deviceCodeGranter.DeviceCodeGrant (apiauth/device_granter.go); per-RFC authorization_pending / slow_down / access_denied / expired_token errors emitted |
Full RFC 8628 §3.5 polling state machine |
| Client SDK | Implemented | client.AuthClient.DeviceAuthorization, PollDeviceToken (client/device_grant.go) |
PollDeviceToken returns ErrAuthorizationPending, ErrSlowDown and the other RFC 8628 sentinels for its polling loop, and a *client.TokenError for any other error code. DeviceAuthorization returns *TokenError too (0.1.40). |
Persistence interface (DeviceAuthorizationStore) |
Implemented | OneAuthConfig.DeviceAuthStore (apiauth/oneauth.go); backends via deviceauthtest.RunAll contract suite |
FS/GORM/GAE all implement |
AS metadata advertisement (device_authorization_endpoint) |
Implemented | ASServerMetadata.DeviceAuthorizationEndpoint (apiauth/as_metadata.go) |
Per RFC 8628 §4 |
| Test coverage | Implemented | apiauth/device_auth_grant_test.go, apiauth/device_flow_mount_test.go, apiauth/device_verification_handler_test.go, tests/e2e/device_flow_test.go |
E2E exercises the polling state machine |
When NOT to use it ¶
- Clients with a browser already. Use auth-code + PKCE — better UX (no
device-code typing) and no polling. - Voice-only assistants and notification-driven flows. Device flow
assumes the user can read a short code; better fit is OIDC CIBA where
the AS pushes a prompt to the user instead. - High-frequency machine-to-machine token issuance. Device flow has
human-in-the-loop latency built in. Use client_credentials or
jwt-bearer grant.
Related RFCs ¶
- RFC 6749 — the framework that 8628 extends with a new grant
- OAuth 2.1 draft — keeps 8628 unchanged
- RFC 9700 — §4.4 mix-up attack applies to the device flow too (
issnot applicable here, but caller authentication does) - OIDC CIBA — backchannel auth; alternative when even short-code display isn’t possible