Skip to content

Commit 0474e1f

Browse files
committed
fix: open login link in default browser
1 parent 0980a5e commit 0474e1f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: pkg/api/auth0/device_code.go

+20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"io/ioutil"
88
"net/http"
9+
"os/exec"
10+
"runtime"
911
)
1012

1113
type DeviceCodeRequest struct {
@@ -66,6 +68,24 @@ func RequestDeviceCode() (string, error) {
6668

6769
fmt.Println("open this url in your browser:")
6870
fmt.Println(response.VerificationUrlComplete)
71+
err = openUrl(response.VerificationUrlComplete)
72+
if err != nil {
73+
return "", fmt.Errorf("failed to open url in browser: %v", err)
74+
}
6975

7076
return response.DeviceCode, nil
7177
}
78+
79+
func openUrl(url string) error {
80+
var cmd *exec.Cmd
81+
switch runtime.GOOS {
82+
case "windows":
83+
cmd = exec.Command("cmd", "/c", "start", url)
84+
case "darwin":
85+
cmd = exec.Command("open", url)
86+
default:
87+
cmd = exec.Command("xdg-open", url)
88+
}
89+
90+
return cmd.Start()
91+
}

0 commit comments

Comments
 (0)