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

Function AddAuthTokenHeader

api/http_client.go:186–201  ·  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

184// token source. It is the backward-compatible entry point retained for external callers of this package; gh's own code
185// authenticates through the refresh-aware AddAuthTokenHeaderWithRefresh.
186func AddAuthTokenHeader(rt http.RoundTripper, cfg config) http.RoundTripper {
187 return addAuthHeaderRoundTripper(rt, func(host string) string {
188 token, _ := cfg.ActiveToken(host)
189 if token == "" {
190 // The request may be aimed at a host's api_host, which gh is
191 // not logged in to and so has no token of its own. Fall back
192 // to the token of the host it stands in for. This only ever
193 // adds a token where there would have been none, so hosts we
194 // already authenticate keep resolving exactly as before.
195 if canonicalHost, ok := cfg.HostForAPIHost(host); ok {
196 token, _ = cfg.ActiveToken(canonicalHost)
197 }
198 }
199 return token
200 })
201}
202
203// AddAuthTokenHeaderWithRefresh is the refresh-aware counterpart of AddAuthTokenHeader. It renews a near-expiry
204// 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