Skip to main content

Module device

Module device 

Source
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Β§

DeviceAuthorizationForm
Form body for POST /device_authorization (RFC 8628 Β§3.1).
DeviceAuthorizationResponse
Success body for POST /device_authorization (RFC 8628 Β§3.2).
DeviceDecisionBody
Body for the approve/deny verification actions.
DeviceDecisionResponse
Result of an approve/deny action.
DeviceVerificationInfo
Render data returned to the verification page so it can show the user what they are about to authorize.
DeviceVerificationQuery
Query for the verification page render data (GET /device_verification).
MainFrontendOauthDeviceApiDoc πŸ”’

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_code is 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 to user_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_uri is 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 ControllerError for a user_code that 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_code on collision with another still-pending grant so a clash cannot surface as a 500.
is_pending_user_code_collision πŸ”’
True when err is the pending-user_code unique-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_code and gather the render data.
normalize_user_code πŸ”’
Normalize a user-entered user_code into the canonical XXXX-XXXX shape.
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 scope optional).