MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / headlessAuth

Function headlessAuth

app/cli/cmd/auth_login.go:112–139  ·  view source on GitHub ↗
(loginURL *url.URL)

Source from the content-addressed store, hash-verified

110}
111
112func headlessAuth(loginURL *url.URL) error {
113 // Remove cli-callback query parameter to indicate the server to show it inline
114 q := loginURL.Query()
115 q.Set("callback", "")
116 loginURL.RawQuery = q.Encode()
117 fmt.Printf("To authenticate, click on the following link and paste the result back here\n\n %s\n\n", loginURL.String())
118
119 fmt.Print("Enter Token: ")
120 token, err := readPasswordFromTerminal()
121 if err != nil {
122 return fmt.Errorf("retrieving password from stdin: %w", err)
123 }
124
125 // We just want to check that it is a token, the actual verification will happen when it is sent to the server
126 // To be clear, this is just a best effort sanity check
127 if _, _, err := new(jwt.Parser).ParseUnverified(string(token), &jwt.MapClaims{}); err != nil {
128 return errors.New("invalid token")
129 }
130
131 if err := saveAuthToken(string(token)); err != nil {
132 return fmt.Errorf("storing token in config file: %w", err)
133 }
134
135 fmt.Println("")
136 logger.Info().Msg("login successful!")
137
138 return nil
139}
140
141// Save token to config file
142func saveAuthToken(token string) error {

Callers 1

interactiveAuthFunction · 0.85

Calls 7

saveAuthTokenFunction · 0.85
PrintMethod · 0.80
readPasswordFromTerminalFunction · 0.70
SetMethod · 0.65
StringMethod · 0.65
InfoMethod · 0.65
QueryMethod · 0.45

Tested by

no test coverage detected