10 cards
Minimum endpoints
`/device/code` (issue codes), `/device` (code-entry page), `/device/approve` (confirm), `/token` (polling).
Store the device_code as a hash
If the DB/Redis leaks, the attacker does not have the original device_code to poll with.
user_code → device_code mapping
A separate Redis key so the code-entry page can find the request to confirm.
State machine
`pending → approved | denied | expired`, `approved → consumed` after being exchanged for a token exactly once.
Redis TTL
Equal to `expires_in`, so expired codes disappear without a cleanup job.
last_poll_at
Store the time of the latest poll to detect polling faster than the interval and return `slow_down`.
One-time consume
Move the state to consumed with an atomic operation so two parallel requests cannot both receive a token.
Bind identity on approve
Store the approving user id in the record so the issued token belongs to the right user.
Rate limit
Apply to `/device/code` per client/IP and to the code-entry page per session/IP.
OAuth errors returned
400 with `error` per RFC 6749 §5.2 and RFC 8628 §3.5.