(loginURL *url.URL)
| 110 | } |
| 111 | |
| 112 | func 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 |
| 142 | func saveAuthToken(token string) error { |
no test coverage detected