-
-
Notifications
You must be signed in to change notification settings - Fork 23
Add OAuth 2.0 authentication with token refresh support #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implement OAuth2Authenticator class that supports: - Token storage (access_token, refresh_token, expires_at) - Automatic token expiration checking via token_expired? - Token refresh via refresh_token! method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds OAuth 2.0 authentication support with automatic token refresh capability to the X API client. The implementation follows the existing authenticator pattern and integrates seamlessly with the client's credential precedence system.
Key changes:
- New
OAuth2Authenticatorclass handling bearer token auth and automatic token refresh - Extended
Clientto accept OAuth 2.0 credentials (client_id, client_secret, refresh_token) - Comprehensive test coverage for OAuth 2.0 flows including token expiration and refresh
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/x/oauth2_authenticator.rb | New authenticator class implementing OAuth 2.0 with token refresh using client credentials |
| lib/x/client_credentials.rb | Extended credential management to support OAuth 2.0 fields and authenticator selection |
| lib/x/client.rb | Updated Client initialization to accept OAuth 2.0 credentials |
| sig/x.rbs | Added type signatures for OAuth2Authenticator and updated Client/ClientCredentials signatures |
| test/x/oauth2_authenticator_test.rb | Comprehensive test suite covering initialization, header generation, expiration checks, and token refresh |
| test/x/client_initialization_test.rb | Reorganized tests into focused test classes and added OAuth 2.0 initialization tests |
| test/test_helper.rb | Added OAuth 2.0 test constants and credential helper method |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # @return [Hash{String => Object}] the parsed response body | ||
| # @raise [Error] if the response indicates an error | ||
| def handle_token_response(response) | ||
| body = JSON.parse(response.body) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
lib/x/oauth2_authenticator.rb
Outdated
| # @api private | ||
| # @return [Net::HTTP::Post] the POST request | ||
| def build_token_request | ||
| request = Net::HTTP::Post.new(TOKEN_URL) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Change TOKEN_URL and TOKEN_HOST from api.x.com to api.twitter.com to match the rest of the client's default API host configuration.
No description provided.