Skip to content

Commit

Permalink
Merge pull request #145 from kaytu-io/fix-approved-plugins
Browse files Browse the repository at this point in the history
fix: open login link in default browser
  • Loading branch information
artaasadi committed May 21, 2024
2 parents 664a039 + 768ee09 commit e092c8c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/api/auth0/device_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os/exec"
"runtime"
)

type DeviceCodeRequest struct {
Expand Down Expand Up @@ -66,6 +68,24 @@ func RequestDeviceCode() (string, error) {

fmt.Println("open this url in your browser:")
fmt.Println(response.VerificationUrlComplete)
err = openUrl(response.VerificationUrlComplete)
if err != nil {
fmt.Println(fmt.Errorf("failed to open url in browser: %v", err))
}

return response.DeviceCode, nil
}

func openUrl(url string) error {
var cmd *exec.Cmd
switch runtime.GOOS {
case "windows":
cmd = exec.Command("cmd", "/c", "start", url)
case "darwin":
cmd = exec.Command("open", url)
default:
cmd = exec.Command("xdg-open", url)
}

return cmd.Start()
}

0 comments on commit e092c8c

Please sign in to comment.