Skip to content

Commit

Permalink
Make CLI Token Browser opener configurable, EchoOpener uses stderr (#50)
Browse files Browse the repository at this point in the history
* Opener: Display URL when opening, allow overriding

Currently the program silently launches the auth flow URL, which can be
confusing if it doesn't happen or the user switches away. Instead, notify
that the user is about to be directed to a URL.

Also add a way to set a custom opener on a CLI token source, for further
experimentation with this (e.g if we want to add a confirmation prompt)

* add a newline there, so wrapped output follows

* Do not output

This has the potential to be a pretty breaking change, so back out
the writing of info for now (will experiment internally)
  • Loading branch information
lstoll-sfdc authored Dec 8, 2023
1 parent f44248e commit d3cbcb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions clitoken/local_token_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ func WithRenderer(renderer Renderer) LocalOIDCTokenSourceOpt {
}
}

// WithOpener sets a custom handler for launching URLs on the user's system.
// This is used to kick them in to the auth flow.
func WithOpener(opener Opener) LocalOIDCTokenSourceOpt {
return func(s *LocalOIDCTokenSource) {
s.opener = opener
}
}

// Token attempts to a fetch a token. The user will be required to open a URL
// in their browser and authenticate to the upstream IdP.
func (s *LocalOIDCTokenSource) Token(ctx context.Context) (*oidc.Token, error) {
Expand Down
2 changes: 1 addition & 1 deletion clitoken/opener.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ func (o *CommandOpener) Open(ctx context.Context, url string) error {
type EchoOpener struct{}

func (o *EchoOpener) Open(ctx context.Context, url string) error {
_, err := fmt.Printf("To continue, open this URL in a browser: %s\n", url)
_, err := fmt.Fprintf(os.Stderr, "To continue, open this URL in a browser: %s\n", url)
return err
}

0 comments on commit d3cbcb7

Please sign in to comment.