Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for ssh clients when logging in #180

Merged
merged 2 commits into from
Sep 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 23 additions & 8 deletions pkg/login/client_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"os"

"github.com/briandowns/spinner"
"github.com/stripe/stripe-cli/pkg/ansi"
"github.com/stripe/stripe-cli/pkg/config"
"github.com/stripe/stripe-cli/pkg/open"
Expand Down Expand Up @@ -45,16 +46,22 @@ func Login(baseURL string, config *config.Config, input io.Reader) error {
color := ansi.Color(os.Stdout)
fmt.Printf("Your pairing code is: %s\n", color.Bold(links.VerificationCode))

fmt.Printf("Press Enter to open the browser (^C to quit)")
fmt.Fscanln(input)

s := ansi.StartSpinner("Waiting for confirmation...", os.Stdout)
var s *spinner.Spinner
if isSSH() {
fmt.Println(fmt.Sprintf("To authenticate with Stripe, please go to: %s", links.BrowserURL))
s = ansi.StartSpinner("Waiting for confirmation...", os.Stdout)
} else {
fmt.Printf("Press Enter to open the browser (^C to quit)")
fmt.Fscanln(input)

err = openBrowser(links.BrowserURL)
if err != nil {
msg := fmt.Sprintf("Failed to open browser, please go to %s manually.", links.BrowserURL)
ansi.StopSpinner(s, msg, os.Stdout)
s = ansi.StartSpinner("Waiting for confirmation...", os.Stdout)

err = openBrowser(links.BrowserURL)
if err != nil {
msg := fmt.Sprintf("Failed to open browser, please go to %s manually.", links.BrowserURL)
ansi.StopSpinner(s, msg, os.Stdout)
s = ansi.StartSpinner("Waiting for confirmation...", os.Stdout)
}
}

//Call poll function
Expand Down Expand Up @@ -125,3 +132,11 @@ func getLinks(baseURL string, deviceName string) (*Links, error) {

return &links, nil
}

func isSSH() bool {
if os.Getenv("SSH_TTY") != "" || os.Getenv("SSH_CONNECTION") != "" || os.Getenv("SSH_CLIENT") != "" {
return true
}

return false
}