browserGet simulates a user completing the authorization-code flow by opening the URL: it follows the authorize redirect to the local callback, delivering the code to the manager's callback server. Used both as an openURL seam and inside prompter hooks.
(rawurl string)
| 181 | // the code to the manager's callback server. Used both as an openURL seam and |
| 182 | // inside prompter hooks. |
| 183 | func browserGet(rawurl string) error { |
| 184 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 185 | defer cancel() |
| 186 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawurl, nil) |
| 187 | if err != nil { |
| 188 | return err |
| 189 | } |
| 190 | resp, err := http.DefaultClient.Do(req) |
| 191 | if err != nil { |
| 192 | return err |
| 193 | } |
| 194 | _, _ = io.Copy(io.Discard, resp.Body) |
| 195 | return resp.Body.Close() |
| 196 | } |
| 197 | |
| 198 | func testLogger() *slog.Logger { |
| 199 | return slog.New(slog.NewTextHandler(io.Discard, nil)) |
no test coverage detected