@@ -26,6 +26,7 @@ import (
2626 "strconv"
2727 "strings"
2828 "time"
29+ "unicode/utf8"
2930
3031 "golang.org/x/oauth2"
3132)
@@ -87,12 +88,16 @@ func UseDelegatedTokenAuth(ctx context.Context, headerParams *map[string]string,
8788
8889// SetAuthKeys sets the appropriate values in the headers parameter.
8990func SetAuthKeys (ctx context.Context , headerParams * map [string ]string , keys ... [2 ]string ) {
90- if ctx != nil {
91- for _ , key := range keys {
92- if auth , ok := ctx .Value (ContextAPIKeys ).(map [string ]APIKey ); ok {
93- if apiKey , ok := auth [key [0 ]]; ok {
94- (* headerParams )[key [1 ]] = apiKey .Key
95- }
91+ if ctx == nil {
92+ return
93+ }
94+ if bearerToken , ok := ctx .Value (ContextBearerToken ).(string ); ok {
95+ (* headerParams )[authorizationHeader ] = fmt .Sprintf (bearerTokenFormat , bearerToken )
96+ }
97+ for _ , key := range keys {
98+ if auth , ok := ctx .Value (ContextAPIKeys ).(map [string ]APIKey ); ok {
99+ if apiKey , ok := auth [key [0 ]]; ok {
100+ (* headerParams )[key [1 ]] = apiKey .Key
96101 }
97102 }
98103 }
@@ -181,6 +186,10 @@ func (c *APIClient) CallAPI(request *http.Request) (*http.Response, error) {
181186 dump = valueRegex .ReplaceAll (dump , []byte ("REDACTED" ))
182187 }
183188 }
189+ if bearerToken , ok := newRequest .Context ().Value (ContextBearerToken ).(string ); ok {
190+ valueRegex := regexp .MustCompile (fmt .Sprintf ("(?m)%s" , bearerToken ))
191+ dump = valueRegex .ReplaceAll (dump , []byte ("REDACTED" ))
192+ }
184193 log .Printf ("\n %s\n " , string (dump ))
185194 }
186195 resp , requestErr := c .Cfg .HTTPClient .Do (newRequest )
0 commit comments