mirror of
https://gitlab.com/TECHNOFAB/go-copilot-proxy.git
synced 2025-12-11 22:10:06 +01:00
chore: initial commit
This commit is contained in:
commit
595200836c
16 changed files with 1571 additions and 0 deletions
38
internal/cmd/auth.go
Normal file
38
internal/cmd/auth.go
Normal 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.")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue