google: manual testing fixes
I found some errors while manually testing service account impersonation on Azure. This PR includes the fixes that I made. Change-Id: Ia2b194be6c9a7c843e615f9789c8f8203bcbc151 GitHub-Last-Rev: 56907163634bb65457c12320b4081e919cfbbcb2 GitHub-Pull-Request: golang/oauth2#475 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/291209 Reviewed-by: Cody Oss <codyoss@google.com> Trust: Cody Oss <codyoss@google.com> Trust: Tyler Bui-Palsulich <tbp@google.com> Run-TryBot: Cody Oss <codyoss@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -63,9 +64,12 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bodyJson := json.NewDecoder(io.LimitReader(resp.Body, 1<<20))
|
||||
body, err := ioutil.ReadAll(io.LimitReader(resp.Body, 1<<20))
|
||||
if c := resp.StatusCode; c < 200 || c > 299 {
|
||||
return nil, fmt.Errorf("oauth2/google: status code %d: %s", c, body)
|
||||
}
|
||||
var stsResp STSTokenExchangeResponse
|
||||
err = bodyJson.Decode(&stsResp)
|
||||
err = json.Unmarshal(body, &stsResp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oauth2/google: failed to unmarshal response body from Secure Token Server: %v", err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user