Skip to content

feat(auth): implement OAuth 2.0 Device Authorization Flow (RFC 8628)#354

Merged
nycomp merged 6 commits intoweeklyfrom
feature/oauth-device-authorization-flow
Mar 10, 2026
Merged

feat(auth): implement OAuth 2.0 Device Authorization Flow (RFC 8628)#354
nycomp merged 6 commits intoweeklyfrom
feature/oauth-device-authorization-flow

Conversation

@nycomp
Copy link
Copy Markdown
Contributor

@nycomp nycomp commented Feb 26, 2026

Adds support for CLI and device applications to authenticate without embedding a client secret.

Backend (campus)

  • Add DeviceCode model for tracking pending device authorizations
  • Add device authorization flow scheme (OAuth2DeviceAuthorizationFlowScheme)
  • Add OAuth routes (public, no auth required):
    • POST /oauth/device_authorize - request device/user code
    • POST /oauth/token - poll for token (device_code grant type)
    • GET /oauth/device - verification page (HTML)
    • POST /oauth/device/authorize - submit user code authorization
  • Add RFC 8628 token errors: AuthorizationPendingError, SlowDownError,
    ExpiredTokenError, AccessDeniedError
  • Add utility functions: generate_device_code(), generate_user_code()
  • Export ConflictError from errors init.py

Resolves #353

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

ngjunsiang and others added 4 commits February 25, 2026 19:41
Adds support for CLI and device applications to authenticate without
embedding a client secret.

## Backend (campus)
- Add DeviceCode model for tracking pending device authorizations
- Add device authorization flow scheme (OAuth2DeviceAuthorizationFlowScheme)
- Add OAuth routes (public, no auth required):
  - POST /oauth/device_authorize - request device/user code
  - POST /oauth/token - poll for token (device_code grant type)
  - GET /oauth/device - verification page (HTML)
  - POST /oauth/device/authorize - submit user code authorization
- Add RFC 8628 token errors: AuthorizationPendingError, SlowDownError,
  ExpiredTokenError, AccessDeniedError
- Add utility functions: generate_device_code(), generate_user_code()
- Export ConflictError from errors __init__.py

## campus-api-python
- Add OAuth device flow client methods
- Add `oauth` property to AuthRoot
- Add `mode` parameter to Campus.__init__(): "server" (default, requires
  CLIENT_ID/CLIENT_SECRET) or "device" (no credentials required)

Resolves #353

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- test_error_codes_format: skip OAuth token error codes (AUTH_ prefix)
  and inherited str methods when validating error constants
- test_invalid_request_error_has_envelope: allow details to be None
  since not all error types include details by default

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use client_resource[client_id] instead of client_resource.client[client_id]
- Use device_code_resource instead of device_code_resource.device_code
- Use credentials_resource["campus"][user_id] instead of credentials_resource.credentials["campus"]
- Import InvalidClientError and InvalidGrantError from token_errors not auth_errors
- Replace auth_errors.ExpiredTokenError with api_errors.InvalidRequestError
- Fix return type annotation in device_authorization.py

All 13 type-check errors related to OAuth device flow are now fixed.
Remaining 20 errors are pre-existing issues in storage backends.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nycomp nycomp linked an issue Feb 26, 2026 that may be closed by this pull request
- Add group_name and details parameters to StorageError base class
  to support error context across all storage backends
- Add boto3-stubs as dev dependency for type annotations

0 errors, 0 warnings, 0 informations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nycomp nycomp merged commit 23fd6b4 into weekly Mar 10, 2026
4 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.

Add OAuth Device Authorization Flow support

2 participants