feat: Add OAuth 2.0 Device Flow Authentication#23
Merged
Conversation
Implements OAuth 2.0 Device Flow Authentication (RFC 8628) for CLI-friendly GitHub auth. Features: - DeviceFlowAuthentication strategy implementing AuthenticationStrategy - DeviceFlowCallback interface for handling flow events - DeviceFlowHttpClient interface for testable HTTP operations - DefaultDeviceFlowHttpClient using native PHP streams - DeviceFlowException for error handling - Complete test coverage (100%) API Implementation: - POST https://github.com/login/device/code (request device code) - POST https://github.com/login/oauth/access_token (poll for token) Handles all flow states: - authorization_pending (continues polling) - slow_down (increases interval by 5s) - access_denied (throws exception) - expired_token (throws exception) - network errors (throws exception) Closes #20
|
Caution Review failedThe pull request is closed. WalkthroughThis PR applies cosmetic formatting corrections across source and test files: PHPDoc whitespace normalization (single vs. double spaces), removal of unnecessary blank lines, and minor docblock cleanup. No functional logic or control flow is altered. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Possibly related PRs
Poem
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements OAuth 2.0 Device Flow Authentication (RFC 8628) for CLI-friendly GitHub authentication.
This PR adds a complete device flow authentication strategy that enables headless/CLI applications to authenticate with GitHub without requiring a browser on the device.
Implementation Details
Core Components
DeviceFlowAuthentication - Main strategy implementing
AuthenticationStrategyTokenAuthenticatorfor use with ConnectorDeviceFlowCallback - Interface for handling flow events
onCodeReady()- Display verification URI and user codeonPolling()- Update UI during pollingonSuccess()- Handle successful authorizationonError()- Handle flow errorsDeviceFlowHttpClient - Testable HTTP interface
DefaultDeviceFlowHttpClient- Uses PHP's native streamsDeviceFlowException - Error handling
API Implementation
Correctly implements GitHub's device flow endpoints:
POST https://github.com/login/device/code- Request device codePOST https://github.com/login/oauth/access_token- Poll for access tokenFlow State Handling
authorization_pending- Continues pollingslow_down- Increases interval by 5 secondsaccess_denied- Throws exception with error detailsexpired_token- Throws exception when code expiresTest Coverage
Quality Gates
declare(strict_types=1))Usage Example
Closes
Closes #20
References
Summary by CodeRabbit
Release Notes
This release includes code formatting improvements to enhance consistency and readability across the entire codebase and test suite.
✏️ Tip: You can customize this high-level summary in your review settings.