forked from remote/oauth2
Added in fixes found during manual testing of Azure import.
Change-Id: Icf21d58732fdf4e3caaca015bc10d84613d0f423
This commit is contained in:
@@ -96,7 +96,7 @@ func (c *Config) parse(ctx context.Context) (baseCredentialSource, error) {
|
|||||||
} else if c.CredentialSource.File != "" {
|
} else if c.CredentialSource.File != "" {
|
||||||
return fileCredentialSource{File: c.CredentialSource.File, Format: c.CredentialSource.Format}, nil
|
return fileCredentialSource{File: c.CredentialSource.File, Format: c.CredentialSource.Format}, nil
|
||||||
} else if c.CredentialSource.URL != "" {
|
} else if c.CredentialSource.URL != "" {
|
||||||
return urlCredentialSource{URL: c.CredentialSource.URL, Format: c.CredentialSource.Format, ctx: ctx}, nil
|
return urlCredentialSource{URL: c.CredentialSource.URL, Headers: c.CredentialSource.Headers, Format: c.CredentialSource.Format, ctx: ctx}, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("oauth2/google: unable to parse credential source")
|
return nil, fmt.Errorf("oauth2/google: unable to parse credential source")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (its impersonateTokenSource) Token() (*oauth2.Token, error) {
|
|||||||
return nil, fmt.Errorf("oauth2/google: unable to read body: %v", err)
|
return nil, fmt.Errorf("oauth2/google: unable to read body: %v", err)
|
||||||
}
|
}
|
||||||
if c := resp.StatusCode; c < 200 || c > 299 {
|
if c := resp.StatusCode; c < 200 || c > 299 {
|
||||||
return nil, fmt.Errorf("oauth2/google: status code %d: %s", c, body)
|
return nil, fmt.Errorf("oauth2/google: status code %d: %s", c, string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
var accessTokenResp impersonateTokenResponse
|
var accessTokenResp impersonateTokenResponse
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -63,9 +64,12 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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, string(body))
|
||||||
|
}
|
||||||
var stsResp STSTokenExchangeResponse
|
var stsResp STSTokenExchangeResponse
|
||||||
err = bodyJson.Decode(&stsResp)
|
json.Unmarshal(body, &stsResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("oauth2/google: failed to unmarshal response body from Secure Token Server: %v", err)
|
return nil, fmt.Errorf("oauth2/google: failed to unmarshal response body from Secure Token Server: %v", err)
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ func (cs urlCredentialSource) subjectToken() (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("oauth2/google: invalid body in subject token URL query: %v", err)
|
return "", fmt.Errorf("oauth2/google: invalid body in subject token URL query: %v", err)
|
||||||
}
|
}
|
||||||
|
if c := resp.StatusCode; c < 200 || c > 299 {
|
||||||
|
return "", fmt.Errorf("oauth2/google: status code %d: %s", c, string(tokenBytes))
|
||||||
|
}
|
||||||
|
|
||||||
switch cs.Format.Type {
|
switch cs.Format.Type {
|
||||||
case "json":
|
case "json":
|
||||||
|
|||||||
Reference in New Issue
Block a user