MCPcopy Create free account
hub / github.com/cli/cli / configWithTokenRefresher

Function configWithTokenRefresher

pkg/cmd/factory/default.go:269–285  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

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.
269func 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
287func externalHttpClientFunc(ios *iostreams.IOStreams, appVersion string) func() (*http.Client, error) {
288 return func() (*http.Client, error) {

Callers 2

NewFunction · 0.85

Calls 4

NewTokenRefresherFunction · 0.92
DoMethod · 0.65
SetTokenRefresherMethod · 0.65
AuthenticationMethod · 0.65

Tested by 1