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

Function AddAuthTokenHeader

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

205// token source. It is the backward-compatible entry point retained for external callers of this package; gh's own code
206// authenticates through the refresh-aware AddAuthTokenHeaderWithRefresh.
207func AddAuthTokenHeader(rt http.RoundTripper, cfg config) http.RoundTripper {
208 return addAuthHeaderRoundTripper(rt, func(host string) string {
209 token, _ := cfg.ActiveToken(host)
210 if token == "" {
211 // The request may be aimed at a host's api_host, which gh is
212 // not logged in to and so has no token of its own. Fall back
213 // to the token of the host it stands in for. This only ever
214 // adds a token where there would have been none, so hosts we
215 // already authenticate keep resolving exactly as before.
216 if canonicalHost, ok := cfg.HostForAPIHost(host); ok {
217 token, _ = cfg.ActiveToken(canonicalHost)
218 }
219 }
220 return token
221 })
222}
223
224// AddAuthTokenHeaderWithRefresh is the refresh-aware counterpart of AddAuthTokenHeader. It renews a near-expiry
225// 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