Skip to content

feat: add Device Authorization Grant (RFC 8628)#344

Merged
eugenioenko merged 9 commits into
mainfrom
feat/device-auth-grant
May 9, 2026
Merged

feat: add Device Authorization Grant (RFC 8628)#344
eugenioenko merged 9 commits into
mainfrom
feat/device-auth-grant

Conversation

@eugenioenko
Copy link
Copy Markdown
Owner

Summary

  • Implements RFC 8628 Device Authorization Grant for headless devices and CLI tools
  • New POST /oauth2/device_authorization endpoint issuing device_code + user_code
  • User verification UI at /oauth2/device (enter code, approve/deny)
  • Token endpoint support for urn:ietf:params:oauth:grant-type:device_code polling with authorization_pending, slow_down, expired_token, access_denied errors
  • Database migration 008 adding device_codes table
  • Runtime config: device_code_expiration (default 10m), device_code_polling_interval (default 5s)
  • Cleanup integration for expired device codes
  • Discovery document updated with device_authorization_endpoint and grant type
  • Client validation updated to allow urn:ietf:params:oauth:grant-type:device_code grant type

Closes #264

Test plan

  • Unit tests for code generation, DB CRUD, and status transitions (pkg/devicecode/)
  • Handler tests for device authorization endpoint (success, missing client, unknown client, unauthorized grant, invalid scope, wrong method)
  • Token endpoint tests for device code grant (authorization_pending, access_denied, expired_token, success, missing device_code)
  • Security test updated (removed device_code from unsupported grant types list)
  • Full test suite passes (go test -p 1 ./...)
  • Lint clean (golangci-lint run ./...)

🤖 Generated with Claude Code

eugenioenko and others added 9 commits May 9, 2026 14:48
Implements the full device authorization flow for headless devices and
CLI tools. Includes device_authorization endpoint, user verification UI,
token polling with slow_down/authorization_pending/expired_token errors,
and cleanup integration.

Closes #264

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Black-box HTTP tests covering device_authorization endpoint,
token polling, discovery, and error cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add RFC 8628 section references on all validation checks and return paths
- Add "Device Code" option to admin UI grant type selectors
- Regenerate swagger documentation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ints

Replace server-rendered device verification templates with a React page
in the account UI. This leverages the existing OIDC authentication flow
instead of reimplementing login/MFA/passkey handling in the device flow.

- Add /account/api/device/{verify,authorize,deny} API endpoints
- Add Device.tsx page with code input, confirmation, and result states
- Add /device redirect handler for convenience URLs
- Remove server-rendered device_verify/confirm/success/denied templates
- Update verification_uri to use path format (/account/device/{code})
- Add device flow test page to debug-ui

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The verification_uri already points directly to /account/device,
so the /device redirect routes were dead code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Mark device codes as consumed after successful token exchange to
  prevent replay attacks (RFC 8628 §3.5)
- Verify device_code was issued to the requesting client_id before
  exchanging tokens (RFC 8628 §3.4)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Each slow_down response now increases the device code's interval by
5 seconds in the database. Also adds Pragma: no-cache header to the
device authorization response per RFC 6749 §5.1.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase 13 compliance table covering all MUST/SHOULD/MAY requirements,
security considerations checklist, discovery cross-check, and full
test inventory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@eugenioenko eugenioenko merged commit 9ba1f2c into main May 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add Device Authorization Grant (RFC 8628)

1 participant