Skip to content

Commit 4d78a79

Browse files
authored
Merge pull request #174 from j-fuentes/token-encoder
Encode payload in POST to get access token
2 parents 60df3c0 + fe04bc8 commit 4d78a79

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/client/accessToken.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io/ioutil"
77
"net/http"
8+
"net/url"
89
"strings"
910
"time"
1011

@@ -35,10 +36,16 @@ func (c *PreflightClient) getValidAccessToken() (*accessToken, error) {
3536
}
3637

3738
func (c *PreflightClient) renewAccessToken() error {
38-
url := fmt.Sprintf("https://%s/oauth/token", c.credentials.AuthServerDomain)
39+
tokenURL := fmt.Sprintf("https://%s/oauth/token", c.credentials.AuthServerDomain)
3940
audience := "https://preflight.jetstack.io/api/v1"
40-
payload := fmt.Sprintf("grant_type=password&client_id=%s&client_secret=%s&audience=%s&username=%s&password=%s", c.credentials.ClientID, c.credentials.ClientSecret, audience, c.credentials.UserID, c.credentials.UserSecret)
41-
req, err := http.NewRequest("POST", url, strings.NewReader(payload))
41+
payload := url.Values{}
42+
payload.Set("grant_type", "password")
43+
payload.Set("client_id", c.credentials.ClientID)
44+
payload.Set("client_secret", c.credentials.ClientSecret)
45+
payload.Set("audience", audience)
46+
payload.Set("username", c.credentials.UserID)
47+
payload.Set("password", c.credentials.UserSecret)
48+
req, err := http.NewRequest("POST", tokenURL, strings.NewReader(payload.Encode()))
4249
if err != nil {
4350
return errors.Trace(err)
4451
}

0 commit comments

Comments
 (0)