OpenID Connect and OAuth
Device authorization grant
On this page
Introduction
Some devices cannot show a browser: a television, a command-line tool, a box with no screen at all. The "device authorization grant", defined in RFC 8628, lets them sign a person in anyway. People often call it the "device flow" (see the glossary).
The device shows a short code. The person types it somewhere with a browser, such as their phone, and the device polls Signari until they approve. This page explains how Signari keeps that flow safe, because it is open to abuse.
An application must be registered for this grant before it can use it. You do
that with signari client set-grants, as shown in The client must be registered
for the grant.
The three steps
The flow uses three addresses, one for each step:
TextPOST /oauth2/device_authorization the device asksGET|POST /device the person approvesPOST /oauth2/token the device polls
When the device asks, Signari answers with the codes and where to type them:
JSON{ "device_code": "zf1iW_ZV_sSkUpybCsTcYWm9JVShqPKYjRtYpPjfecU", "user_code": "VEUY-LEJF", "verification_uri": "https://auth.example.com/device", "verification_uri_complete": "https://auth.example.com/device?user_code=VEUY-LEJF", "expires_in": 600, "interval": 5}
In this example, user_code is the code the person types, and the standard calls
it the "user code". The device keeps device_code to itself and polls with it.
expires_in is how many seconds the codes last, and interval is how many
seconds to wait between polls.
Both URI forms are returned. The plain one is what a person types. The
_complete variant carries the code, so a person who scans a QR code on the
screen does not type anything.
Device code phishing
An attacker starts the flow on their own device and gets a code. They send it to a victim with a plausible story. The victim types it into the real identity provider, sees a real consent screen, and approves. Then the attacker's device receives the tokens. Nothing in the protocol is violated. The victim authorised the wrong device.
Signari cannot prevent that outright, so it narrows it:
- Ten-minute expiry. Typing eight letters takes far less than ten minutes, and each extra minute gives a phishing attempt more time.
- The confirmation screen names the application, and says that a device is being authorised, with the scopes it will get. That screen is the only place a phished person is told what they are approving.
- Refusing is a first-class button, and refusing says that somebody may have tried to phish them.
- The screen also says so explicitly: "Nobody legitimate will ask you to enter a code they sent you."
The user code
The code is eight characters from a 21-letter alphabet: A–Z without B, I, O, S, Z, and no digits at all. Each exclusion is a common misreading when people copy a code off a screen across a room: I/1/l, O/0, S/5, Z/2, B/8.
That is ~35 bits, comfortably past the 20 RFC 8628 §5.1 asks for against a rate-limited endpoint.
Normalisation forgives case, hyphens, spaces and underscores, and nothing
else. Mapping "confusable" characters to what the reader supposedly meant
would rewrite letters that are in the alphabet, such as L. That turns a
correct code into one that can never match, and the failure is hard to
reproduce. TestNormalizeDoesNotRewriteAlphabetCharacters pins the rule.
Rate limiting
The verification endpoint is rate limited (3/s, burst 10), which is what RFC 8628 §5.1 asks for.
Starting a sign-in is paced too, before anything is stored. A public client gets 60 a minute from one address. A confidential client gets 6,000 a minute, and is paced as itself once it has authenticated.
Each start is a database row for ten minutes. A public client authenticates
nothing, while its ID is on every device running it. So without this pacing,
anybody could have Signari write as many rows as they liked. Past the limit, the
answer is 429 with Retry-After.
There is no attempt counter on each record. When somebody types a wrong code, there is no record to charge it to, since Signari cannot know which one they were aiming at. Such a counter would be a column nothing increments and a function nothing calls, the kind of unreachable code described in security scanning.
What is checked, in what order
The order matters.
The client ID is verified inside the polling transaction, before anything is
consumed. PollDeviceCode marks an approved code redeemed. Checked after it,
anyone holding a leaked device code could present any client ID and have the
approval burned. The legitimate device would then receive only expired_token: a
denial of service against a completed sign-in.
The full order: client ID → expiry → already-redeemed → polling interval → status.
The polling interval is checked before the status. So a device that hammers the endpoint is slowed whether or not the person has approved yet. Checking it after would apply the rule only while approval is still pending.
slow_down adds five seconds to the stored interval and persists it, per RFC 8628
§3.5. So the longer interval is enforced, not only advised.
The client must be registered for the grant
An application runs a device flow only when it is registered for the device
grant. The column default, {authorization_code,refresh_token}, does not
include it. RFC 6749 §5.2 names the error for an application that is not
registered. unauthorized_client is "The authenticated client is not
authorized to use this authorization grant type".
The check lives in one place that every grant passes through, plus the device authorization endpoint. Gating each grant in the handler that serves it would let one be missed.
Both are needed. The token-endpoint check alone would let an application that may not finish a device flow still start one. It could therefore still display a code to a person, and ask them to approve it, which is the step device code phishing relies on.
Token exchange is excluded from the shared check on purpose. It is authorised by
its own may_exchange column, together with the audiences the client may
exchange for, which a grant-type list cannot express.
To register the device grant for an application, alongside the authorization code grant, run:
Shellsignari client set-grants -client-id <id> \ -grant-types authorization_code,urn:ietf:params:oauth:grant-type:device_code
Verified end to end
Against a running Signari, each of these requests gets the answer shown:
| poll before approval | authorization_pending |
| poll again immediately | slow_down |
| another client presents the code | invalid_grant, nothing consumed |
| unknown device code | expired_token |
| type the code signed in | confirmation naming Group Test (grouptest), scopes openid, profile |
| approve, then poll | tokens issued |
| replay the same device code | expired_token, single use |
In the ID token that is issued:
submatches the person who approved;amr, the methods they signed in with, is["pwd"], which matches how they signed in;sidbinds it to the browser session that granted it.
Single credential path
Tokens are minted through mintSet, the same function every other grant uses. So
a device grant gets the same Demonstrating Proof of Possession (DPoP)
binding, resource indicators, group claims and audit
trail. A second minting path could leave one of them out.
Unknown, expired and already-redeemed device codes all answer expired_token.
Telling a caller that a code once existed would help them guess.
Abandoned authorizations are swept by the janitor, Signari's clean-up job, an hour after expiry. Each row holds two code hashes, so an unfinished sign-in does not leave them behind.