Skip to content

Commit

Permalink
show qrcode
Browse files Browse the repository at this point in the history
  • Loading branch information
hickford committed Oct 13, 2023
1 parent ea99a5e commit 27ff133
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ var configByHost = map[string]oauth2.Config{
var (
verbose bool
// populated by GoReleaser https://goreleaser.com/cookbooks/using-main.version
version = "dev"
version = "dev"
qrencodeType string
)

func getVersion() string {
Expand Down Expand Up @@ -139,6 +140,7 @@ func main() {
flag.BoolVar(&verbose, "verbose", false, "log debug information to stderr")
var device bool
flag.BoolVar(&device, "device", false, "instead of opening a web browser locally, print a code to enter on another device")
flag.StringVar(&qrencodeType, "qr", "", "qrencode type")
flag.Usage = func() {
printVersion()
fmt.Fprintln(os.Stderr, "usage: git credential-oauth [<options>] <action>")
Expand Down Expand Up @@ -437,6 +439,23 @@ func getDeviceToken(ctx context.Context, c oauth2.Config) (*oauth2.Token, error)
if verbose {
fmt.Fprintf(os.Stderr, "%+v\n", deviceAuth)
}
if deviceAuth.VerificationURIComplete == "" {
// TODO: delete me
deviceAuth.VerificationURIComplete = deviceAuth.VerificationURI + "?code=" + deviceAuth.UserCode
}
if deviceAuth.VerificationURIComplete != "" && qrencodeType != "" {
qrencodePath, err := exec.LookPath("qrencode")
if err == nil {
cmd := exec.Command(qrencodePath, "-t", qrencodeType, deviceAuth.VerificationURIComplete)
bytes, err := cmd.CombinedOutput()
if err != nil {
log.Fatalln(err)
}
if err == nil {
fmt.Fprintf(os.Stderr, "%s\n", bytes)
}
}
}
fmt.Fprintf(os.Stderr, "Please enter code %s at %s\n", deviceAuth.UserCode, deviceAuth.VerificationURI)
return c.DeviceAccessToken(ctx, deviceAuth)
}
Expand Down

0 comments on commit 27ff133

Please sign in to comment.