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

Password prompt when user defined but not password #116

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cli/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package cli

import (
"fmt"
"net/http"
"syscall"

"golang.org/x/term"
)

// AuthParam describes an auth input parameter for an AuthHandler.
Expand Down Expand Up @@ -42,6 +46,18 @@ func (a *BasicAuth) Parameters() []AuthParam {

// OnRequest gets run before the request goes out on the wire.
func (a *BasicAuth) OnRequest(req *http.Request, key string, params map[string]string) error {
_, usernamePresent := params["username"]
_, passwordPresent := params["password"]

if usernamePresent && !passwordPresent {
fmt.Print("password: ")
inputPassword, err := term.ReadPassword(syscall.Stdin)
if err == nil {
params["password"] = string(inputPassword)
}
fmt.Println()
}

req.SetBasicAuth(params["username"], params["password"])
return nil
}