From 8b1d76fa042330bf6fcfbda4a3da5f69d1b64f5f Mon Sep 17 00:00:00 2001 From: Cody Oss Date: Wed, 13 Jan 2021 08:23:33 -0700 Subject: [PATCH] google: restore 1.11 compatibility NewRequestWithContext requires 1.13. As this is just a convenience we should try to retatin the 1.11 compatibility by using NewRequest then calling WithContext instead. Change-Id: I6208a92061b208a119fdf04fd561a3e4d22bc547 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/283535 Reviewed-by: Tyler Bui-Palsulich Trust: Tyler Bui-Palsulich Trust: Cody Oss Run-TryBot: Tyler Bui-Palsulich TryBot-Result: Go Bot --- google/internal/externalaccount/sts_exchange.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/google/internal/externalaccount/sts_exchange.go b/google/internal/externalaccount/sts_exchange.go index d7f54e0..c7d85a3 100644 --- a/google/internal/externalaccount/sts_exchange.go +++ b/google/internal/externalaccount/sts_exchange.go @@ -8,12 +8,13 @@ import ( "context" "encoding/json" "fmt" - "golang.org/x/oauth2" "io" "net/http" "net/url" "strconv" "strings" + + "golang.org/x/oauth2" ) // ExchangeToken performs an oauth2 token exchange with the provided endpoint. @@ -40,11 +41,12 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan authentication.InjectAuthentication(data, headers) encodedData := data.Encode() - req, err := http.NewRequestWithContext(ctx, "POST", endpoint, strings.NewReader(encodedData)) + req, err := http.NewRequest("POST", endpoint, strings.NewReader(encodedData)) if err != nil { return nil, fmt.Errorf("oauth2/google: failed to properly build http request: %v", err) } + req = req.WithContext(ctx) for key, list := range headers { for _, val := range list { req.Header.Add(key, val)