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))
| 281 | // existing token. Injection runs once because Authentication returns a single shared AuthConfig; if the plain client |
| 282 | // cannot be built, injection is skipped and token refresh simply stays inapplicable rather than failing the command. |
| 283 | func configWithTokenRefresher(cfgFunc func() (gh.Config, error), plainClientFunc func() (*http.Client, error)) func() (gh.Config, error) { |
| 284 | var once sync.Once |
| 285 | return func() (gh.Config, error) { |
| 286 | cfg, err := cfgFunc() |
| 287 | if err != nil { |
| 288 | return nil, err |
| 289 | } |
| 290 | once.Do(func() { |
| 291 | plainClient, err := plainClientFunc() |
| 292 | if err != nil { |
| 293 | return |
| 294 | } |
| 295 | cfg.Authentication().SetTokenRefresher(authflow.NewTokenRefresher(plainClient)) |
| 296 | }) |
| 297 | return cfg, nil |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | func externalHttpClientFunc(ios *iostreams.IOStreams, appVersion string) func() (*http.Client, error) { |
| 302 | return func() (*http.Client, error) { |