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

Function AddAuthTokenHeader

api/http_client.go:234–249  ·  view source on GitHub ↗

AddAuthTokenHeader adds an authentication token header for the host specified by the request, using the primitive token source. It is the backward-compatible entry point retained for external callers of this package; gh's own code authenticates through the refresh-aware AddAuthTokenHeaderWithRefresh

(rt http.RoundTripper, cfg config)

Source from the content-addressed store, hash-verified

232// token source. It is the backward-compatible entry point retained for external callers of this package; gh's own code
233// authenticates through the refresh-aware AddAuthTokenHeaderWithRefresh.
234func AddAuthTokenHeader(rt http.RoundTripper, cfg config) http.RoundTripper {
235 return addAuthHeaderRoundTripper(rt, func(host string) string {
236 token, _ := cfg.ActiveToken(host)
237 if token == "" {
238 // The request may be aimed at a host's api_host, which gh is
239 // not logged in to and so has no token of its own. Fall back
240 // to the token of the host it stands in for. This only ever
241 // adds a token where there would have been none, so hosts we
242 // already authenticate keep resolving exactly as before.
243 if canonicalHost, ok := cfg.HostForAPIHost(host); ok {
244 token, _ = cfg.ActiveToken(canonicalHost)
245 }
246 }
247 return token
248 })
249}
250
251// AddAuthTokenHeaderWithRefresh is the refresh-aware counterpart of AddAuthTokenHeader. It renews a near-expiry
252// token before attaching it, and is the attach helper gh's own code uses so its requests go through the

Callers 2

NewHTTPClientFunction · 0.85

Calls 3

ActiveTokenMethod · 0.65
HostForAPIHostMethod · 0.65

Tested by 1