configWithTokenRefresher returns a config accessor that injects the OAuth token refresher into the AuthConfig the first time the configuration is resolved, so refreshable credentials can be renewed during ordinary commands. The refresher uses a plain HTTP client that sets no auth headers, since the
(cfgFunc func() (gh.Config, error), plainClientFunc func() (*http.Client, error))
| 267 | // existing token. Injection runs once because Authentication returns a single shared AuthConfig; if the plain client |
| 268 | // cannot be built, injection is skipped and token refresh simply stays inapplicable rather than failing the command. |
| 269 | func configWithTokenRefresher(cfgFunc func() (gh.Config, error), plainClientFunc func() (*http.Client, error)) func() (gh.Config, error) { |
| 270 | var once sync.Once |
| 271 | return func() (gh.Config, error) { |
| 272 | cfg, err := cfgFunc() |
| 273 | if err != nil { |
| 274 | return nil, err |
| 275 | } |
| 276 | once.Do(func() { |
| 277 | plainClient, err := plainClientFunc() |
| 278 | if err != nil { |
| 279 | return |
| 280 | } |
| 281 | cfg.Authentication().SetTokenRefresher(authflow.NewTokenRefresher(plainClient)) |
| 282 | }) |
| 283 | return cfg, nil |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | func externalHttpClientFunc(ios *iostreams.IOStreams, appVersion string) func() (*http.Client, error) { |
| 288 | return func() (*http.Client, error) { |