Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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 @@ -149,6 +150,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 @@ -475,6 +477,19 @@ func getDeviceToken(ctx context.Context, c oauth2.Config) (*oauth2.Token, error)
if verbose {
fmt.Fprintf(os.Stderr, "%+v\n", deviceAuth)
}
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