Skip to content

Commit

Permalink
Revert to using browser.OpenURL for SSO flow default (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaWilkes authored Sep 28, 2022
1 parent 84e2f49 commit c706b2b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
1 change: 0 additions & 1 deletion pkg/assume/assume.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ func AssumeCommand(c *cli.Context) error {

// now build the actual command to run - e.g. 'firefox --new-tab <URL>'
args := l.LaunchCommand(consoleURL, con.Profile)

cmd, err := forkprocess.New(args...)
if err != nil {
return err
Expand Down
36 changes: 21 additions & 15 deletions pkg/cfaws/assumer_aws_sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/aws/smithy-go"
"github.com/bigkevmcd/go-configparser"
"github.com/common-fate/granted/pkg/browser"
grantedConfig "github.com/common-fate/granted/pkg/config"
"github.com/common-fate/granted/pkg/debug"
"github.com/fatih/color"
"github.com/pkg/browser"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -194,21 +195,26 @@ func SSODeviceCodeFlowFromStartUrl(ctx context.Context, cfg aws.Config, startUrl
return nil, err
}

browserCommand := browser.OpenCommand() // we default to running 'open <URL>'

if config.CustomSSOBrowserPath != "" {
// replace the 'open' command with a call to the custom browser path.
browserCommand = config.CustomSSOBrowserPath
}
cmd := exec.Command(browserCommand, url)
err = cmd.Start()
if err != nil {
return nil, err
}
// detach from this new process because it continues to run
err = cmd.Process.Release()
if err != nil {
return nil, err
cmd := exec.Command(config.CustomSSOBrowserPath, url)
err = cmd.Start()
if err != nil {
// fail silently
debug.Fprintf(debug.VerbosityDebug, color.Error, err.Error())
} else {
// detatch from this new process because it continues to run
err = cmd.Process.Release()
if err != nil {
// fail silently
debug.Fprintf(debug.VerbosityDebug, color.Error, err.Error())
}
}
} else {
err = browser.OpenURL(url)
if err != nil {
// fail silently
debug.Fprintf(debug.VerbosityDebug, color.Error, err.Error())
}
}

fmt.Fprintln(color.Error, "\nAwaiting authentication in the browser...")
Expand Down
17 changes: 0 additions & 17 deletions pkg/forkprocess/forkprocess_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package forkprocess

import (
"os/exec"
"os/user"
"strconv"

"github.com/pkg/errors"
)
Expand All @@ -20,22 +18,7 @@ type Process struct {
// New creates a new Process with the current user's user and group ID.
// Call Start() on the returned process to actually it.
func New(args ...string) (*Process, error) {
u, err := user.Current()
if err != nil {
return nil, errors.Wrap(err, "getting current user")
}
uid, err := strconv.ParseUint(u.Uid, 10, 32)
if err != nil {
return nil, errors.Wrapf(err, "parsing uid (%s)", u.Uid)
}
gid, err := strconv.ParseUint(u.Gid, 10, 32)
if err != nil {
return nil, errors.Wrapf(err, "parsing gid (%s)", u.Uid)
}

p := Process{
UID: uint32(uid),
GID: uint32(gid),
Args: args,
}
return &p, nil
Expand Down

0 comments on commit c706b2b

Please sign in to comment.