mirror of
https://gitlab.com/TECHNOFAB/go-copilot-proxy.git
synced 2025-12-11 22:10:06 +01:00
39 lines
1 KiB
Go
39 lines
1 KiB
Go
|
|
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.")
|
||
|
|
}
|