-
Notifications
You must be signed in to change notification settings - Fork 396
Fix OpenCode GitHub Copilot authentication detection #494
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
Fix OpenCode GitHub Copilot authentication detection #494
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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 |
Summary of ChangesHello @mcbodge, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where OpenCode failed to detect successful GitHub Copilot authentication, leading to a 'Not Logged In' status in the setup wizard. The changes ensure that GitHub Copilot is properly recognized as an authentication provider and that its OAuth refresh tokens are correctly identified, allowing users to proceed with the application setup seamlessly. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request correctly addresses the GitHub Copilot authentication detection issue by adding the necessary providers and updating the token validation logic to include refresh tokens. The changes are clear and effectively solve the problem. I've included one suggestion to refactor the token checking logic for better conciseness and maintainability by reusing an existing helper function.
| if (auth.type === 'oauth') { | ||
| if ( | ||
| (typeof auth.access === 'string' && auth.access) || | ||
| (typeof auth.refresh === 'string' && auth.refresh) | ||
| ) { | ||
| return true; | ||
| } | ||
| } | ||
| // Also check for access_token field directly | ||
| if (typeof auth.access_token === 'string' && auth.access_token) { | ||
| return true; | ||
| } | ||
| // Check for refresh_token field directly | ||
| if (typeof auth.refresh_token === 'string' && auth.refresh_token) { | ||
| return true; | ||
| } |
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.
This logic is correct, but it can be made more concise and less repetitive by using the existing hasNonEmptyStringField helper function, which is defined earlier in this file. This will improve readability and maintainability by reducing duplicated code.
if (auth.type === 'oauth' && hasNonEmptyStringField(auth, ['access', 'refresh'])) {
return true;
}
// Also check for access_token/refresh_token fields directly
if (hasNonEmptyStringField(auth, ['access_token', 'refresh_token'])) {
return true;
}
Problem
When users authenticate with OpenCode using GitHub Copilot (
opencode auth login→ GitHub Copilot), the app fails to detect the authentication during the setup wizard. The UI shows "Not Logged In" even though the user has successfully authenticated.Root Cause
Two issues in
libs/platform/src/system-paths.ts:Missing provider in detection list: The
OPENCODE_PROVIDERSarray didn't includegithub-copilotorcopilot, so the auth detection completely ignored GitHub Copilot credentials in the auth file.Only checking
accesstokens: ThehasProviderOAuth()function only checked for non-emptyaccesstokens. However, GitHub Copilot uses OAuth refresh tokens - the auth file stores arefreshtoken while theaccessfield remains empty until the token is used:{ "github-copilot": { "type": "oauth", "refresh": "ghu_xxxxx", "access": "", "expires": 0 } }Solution
github-copilotandcopilotto theOPENCODE_PROVIDERSlisthasProviderOAuth()to check for eitheraccessORrefreshtokens whentypeisoauthTesting
~/.local/share/opencode/auth.jsonon WindowsAffected Components
libs/platform/src/system-paths.ts- Auth detection logic