mirror of
https://github.com/golang/oauth2.git
synced 2025-07-21 00:00:09 +08:00
Adding required client_secret credential.
This commit is contained in:
parent
03e5fbeae0
commit
de4c4313f9
@ -175,6 +175,7 @@ func (c *Config) FetchToken(existing *Token) (*Token, error) {
|
||||
}
|
||||
err := c.updateToken(existing, url.Values{
|
||||
"grant_type": {"refresh_token"},
|
||||
"client_secret": {c.opts.ClientSecret},
|
||||
"refresh_token": {existing.RefreshToken},
|
||||
})
|
||||
return existing, err
|
||||
|
@ -65,6 +65,28 @@ func TestExchangePayload(t *testing.T) {
|
||||
conf.Exchange("exchange-code")
|
||||
}
|
||||
|
||||
func TestRefreshPayload(t *testing.T) {
|
||||
oldDefaultTransport := http.DefaultTransport
|
||||
defer func() {
|
||||
http.DefaultTransport = oldDefaultTransport
|
||||
}()
|
||||
conf := newTestConf()
|
||||
http.DefaultTransport = &mockTransport{
|
||||
rt: func(req *http.Request) (resp *http.Response, err error) {
|
||||
headerContentType := req.Header.Get("Content-Type")
|
||||
if headerContentType != "application/x-www-form-urlencoded" {
|
||||
t.Fatalf("Content-Type header is expected to be application/x-www-form-urlencoded, %v found.", headerContentType)
|
||||
}
|
||||
body, _ := ioutil.ReadAll(req.Body)
|
||||
if string(body) != "client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=refresh_token&refresh_token=REFRESH_TOKEN" {
|
||||
t.Fatalf("Exchange payload is found to be %v", string(body))
|
||||
}
|
||||
return nil, errors.New("no response")
|
||||
},
|
||||
}
|
||||
conf.FetchToken(&Token{RefreshToken: "REFRESH_TOKEN"})
|
||||
}
|
||||
|
||||
func TestExchangingTransport(t *testing.T) {
|
||||
oldDefaultTransport := http.DefaultTransport
|
||||
defer func() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user