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)
| 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. |
| 186 | func 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 |