chore: initial commit

This commit is contained in:
technofab 2025-08-05 11:08:53 +02:00
commit 595200836c
No known key found for this signature in database
16 changed files with 1571 additions and 0 deletions

38
internal/cmd/auth.go Normal file
View file

@ -0,0 +1,38 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"gitlab.com/technofab/go-copilot-proxy/internal/auth"
)
var authCmd = &cobra.Command{
Use: "auth",
Short: "Authenticates with GitHub to get the initial OAuth token",
Long: "Initiates the GitHub OAuth device flow to retrieve an OAuth token required for this proxy to work.",
Run: runAuth,
}
func runAuth(cmd *cobra.Command, args []string) {
log.Info().Msg("Starting GitHub authentication for Copilot...")
deviceCodeResp, err := auth.RequestDeviceCode()
if err != nil {
log.Fatal().Err(err).Msg("Failed to request device code")
}
auth.PromptUserForAuth(deviceCodeResp)
accessToken, err := auth.PollForAccessToken(deviceCodeResp)
if err != nil {
log.Fatal().Err(err).Msg("Failed to obtain OAuth token")
}
if err := auth.SaveOAuthToken(accessToken); err != nil {
log.Fatal().Err(err).Msg("Failed to save OAuth token")
}
log.Info().Msg("✅ Authentication successful! The OAuth token has been saved.")
log.Info().Msg("You can now run the 'serve' command.")
}