Skip to content

Fix GitHub Copilot authentication flow - #27

Open
wubin1989 wants to merge 8 commits into
mainfrom
upstream-open-pr-294
Open

wubin1989 wants to merge 8 commits into
mainfrom
upstream-open-pr-294

Conversation

@wubin1989

Copy link
Copy Markdown
Owner

Migrated open PR from upstream for local review.

Upstream: opencode-ai#294
Upstream head: bitomule:improve-copilot-auth @ 5abea93

David Collado Sela and others added 8 commits July 4, 2025 15:34
Implement a simplified 4-step authentication flow:
1. Check if Copilot is enabled in config
2. Check for token in config folder
3. If no token, trigger login flow
4. With token ready, open OpenCode normally

Key improvements:
- Cleaner code structure with helper functions
- Better error handling for auth scenarios
- Support for both hosts.json and apps.json formats
- Proper API version headers for GitHub Copilot
- Clear documentation of client ID usage
- Remove redundant checks for Copilot provider in Validate()
- Improve comments for better clarity
- Maintain the same functionality with cleaner code
- Simplify logging in GitHub Copilot authentication
- Remove redundant logging messages
- Remove unused getMapKeys helper function
- Keep only essential user feedback during authentication
- Implement device flow authentication for GitHub Copilot
- Add token saving to standard ~/.config/github-copilot/hosts.json
- Fix token validation and error handling
- Continue polling when receiving empty responses
- Set environment variables for immediate use of token
- Clean and simplify code implementation
- Remove redundant token saving functions
- Combine hosts.json handling in a single function
- Simplify environment variable checks
- Remove excessive debug logging
- Streamline error handling and code paths
…PILOT_TOKEN

Address the issue where GITHUB_TOKEN conflicts with GitHub CLI tools by:
- Prioritizing GITHUB_COPILOT_TOKEN environment variable over GITHUB_TOKEN
- Updating token loading logic to avoid CLI token conflicts
- Modifying error messages to reference the correct token variable
- Updating documentation to reflect the new token preference

This resolves 401 Unauthorized errors when users have standard GitHub tokens without Copilot scope.

🤖 Generated with opencode
Co-Authored-By: opencode <noreply@opencode.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant