Skip to content

Commit 429d7d6

Browse files
authored
[client] Support BROWSER env for login (#4654)
1 parent 3cdb10c commit 429d7d6

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

client/cmd/login.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"os/exec"
78
"os/user"
89
"runtime"
910
"strings"
@@ -356,13 +357,21 @@ func openURL(cmd *cobra.Command, verificationURIComplete, userCode string, noBro
356357
cmd.Println("")
357358

358359
if !noBrowser {
359-
if err := open.Run(verificationURIComplete); err != nil {
360+
if err := openBrowser(verificationURIComplete); err != nil {
360361
cmd.Println("\nAlternatively, you may want to use a setup key, see:\n\n" +
361362
"https://docs.netbird.io/how-to/register-machines-using-setup-keys")
362363
}
363364
}
364365
}
365366

367+
// openBrowser opens the URL in a browser, respecting the BROWSER environment variable.
368+
func openBrowser(url string) error {
369+
if browser := os.Getenv("BROWSER"); browser != "" {
370+
return exec.Command(browser, url).Start()
371+
}
372+
return open.Run(url)
373+
}
374+
366375
// isUnixRunningDesktop checks if a Linux OS is running desktop environment
367376
func isUnixRunningDesktop() bool {
368377
if runtime.GOOS != "linux" && runtime.GOOS != "freebsd" {

client/ui/client_ui.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"fyne.io/systray"
3232
"github.com/cenkalti/backoff/v4"
3333
log "github.com/sirupsen/logrus"
34-
"github.com/skratchdot/open-golang/open"
3534
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
3635
"google.golang.org/grpc"
3736
"google.golang.org/grpc/credentials/insecure"
@@ -633,7 +632,7 @@ func (s *serviceClient) login(openURL bool) (*proto.LoginResponse, error) {
633632
}
634633

635634
func (s *serviceClient) handleSSOLogin(loginResp *proto.LoginResponse, conn proto.DaemonServiceClient) error {
636-
err := open.Run(loginResp.VerificationURIComplete)
635+
err := openURL(loginResp.VerificationURIComplete)
637636
if err != nil {
638637
log.Errorf("opening the verification uri in the browser failed: %v", err)
639638
return err
@@ -1487,6 +1486,10 @@ func (s *serviceClient) showLoginURL() context.CancelFunc {
14871486
}
14881487

14891488
func openURL(url string) error {
1489+
if browser := os.Getenv("BROWSER"); browser != "" {
1490+
return exec.Command(browser, url).Start()
1491+
}
1492+
14901493
var err error
14911494
switch runtime.GOOS {
14921495
case "windows":

0 commit comments

Comments
 (0)