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 <tbp@google.com>
Trust: Tyler Bui-Palsulich <tbp@google.com>
Trust: Cody Oss <codyoss@google.com>
Run-TryBot: Tyler Bui-Palsulich <tbp@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
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 @@
"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 @@
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)