Expand description
OAuth 2.0 Device Authorization Grant endpoints (RFC 8628).
Two audiences share this module: POST /device_authorization is public and called by
native clients, while the /device_verification* endpoints are session-authed (AuthUser)
and drive the browser consent page.
The DB-touching core of each handler lives in a free function, as in token.rs /
token_service.rs, so it can be unit-tested without actix extractors.
StructsΒ§
- Device
Authorization Form - Form body for
POST /device_authorization(RFC 8628 Β§3.1). - Device
Authorization Response - Success body for
POST /device_authorization(RFC 8628 Β§3.2). - Device
Decision Body - Body for the approve/deny verification actions.
- Device
Decision Response - Result of an approve/deny action.
- Device
Verification Info - Render data returned to the verification page so it can show the user what they are about to authorize.
- Device
Verification Query - Query for the verification page render data (
GET /device_verification). - Main
Frontend πOauth Device ApiDoc
ConstantsΒ§
- DEVICE_
CODE_ πINTERVAL_ SECONDS - Minimum seconds a client should wait between polls of the token endpoint.
- DEVICE_
CODE_ πTTL_ MINUTES - Device code lifetime. Must stay within the DB CHECK ceiling (30 minutes).
- DEVICE_
USER_ πCODE_ MAX_ ATTEMPTS - Number of times a colliding
user_codeis regenerated before giving up.
FunctionsΒ§
- _add_
routes - approve_
device π - Core of
POST /device_verification/approve: persist consent (always, never short-circuited) then approve the pending grant, binding it touser_id. - approve_
device_ verification - Handles
POST /device_verification/approve. - create_
device_ πauthorization - Core of
POST /device_authorization: look up the client, gate on the device-code grant, validate scopes, generate + store the codes, and build the RFC 8628 response.verification_uriis derived as{base_url}/oauth_device. - deny_
device π - Core of
POST /device_verification/deny. - deny_
device_ verification - Handles
POST /device_verification/deny. - device_
authorization - Handles
POST /device_authorizationβ the RFC 8628 device authorization endpoint. - device_
code_ πnot_ found - A
ControllerErrorfor auser_codethat has no still-pending grant. - device_
verification - Handles
GET /device_verificationβ render data for the browser consent page. - insert_
device_ πcode_ retrying_ user_ code - Insert a pending device code, regenerating the
user_codeon collision with another still-pending grant so a clash cannot surface as a 500. - is_
pending_ πuser_ code_ collision - True when
erris the pending-user_codeunique-index violation (the generated code clashed with another still-pending grant). Keyed on the mapped constraint name rather than string-matching the raw DB message. - load_
device_ πverification_ info - Core of
GET /device_verification: look up the pending grant for a (already normalized)user_codeand gather the render data. - normalize_
user_ πcode - Normalize a user-entered
user_codeinto the canonicalXXXX-XXXXshape. - resolve_
device_ πscopes - Resolve and validate the requested scopes against the clientβs registered
scopes. An empty/absent request defaults to the clientβs full scope set
(RFC 8628 Β§3.1 makes
scopeoptional).