Skip to content
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

feat(copilot): adds github copilot login support #469

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nathabonfim59
Copy link
Contributor

As mentioned in #426, currently, we require an external program to generate the Github Copilot oAuthToken.
This PR adds all necessary structures to do this first login within mods.

How to test

  1. Backup and remove your oAuthToken (~/.config/github-copilot)
  2. Remove the cached token (~/.local/share/mods/temp/)
  3. Try to run a new generation using mods
  4. Following the instructions using the DeviceCode authentication flow (it will show in your terminal)

It will automatically ask for login and poll for the authToken every 5 seconds (defined by the API) and perform the generation afterwards

PR Summary

Authentication Refactor:

  • Added new constants for device code and token URLs and the client ID (copilot.go).
  • Introduced new data structures for handling device code and token responses (CopilotDeviceCodeResponse, CopilotDeviceTokenResponse, CopilotFailedRequestResponse, copilotGithubOAuthTokenWrapper, copilotOAuthToken) (copilot.go).

New Functions:

  • Added copilotLogin function to initiate device code authentication and fetch the OAuth token (copilot.go).
  • Added fetchCopilotRefreshToken function to poll for the OAuth token using the device code (copilot.go).
  • Added saveCopilotOAuthToken and copilotRegisterApp functions to save the OAuth token and register the app version (copilot.go).

Refactoring Existing Functions:

  • Modified getCopilotRefreshToken to use the new copilotLogin function for obtaining the OAuth token (copilot.go).
  • Updated getCopilotAccessToken to fetch the OAuth token instead of the refresh token (copilot.go).

- Add full token exchange flow for GitHub Copilot auth
- Store OAuth tokens in config directory
- Register application in versions.json
- Fix API endpoint URLs and request formatting
@nathabonfim59 nathabonfim59 requested a review from caarlos0 as a code owner April 1, 2025 16:21
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.

None yet

1 participant