fix: Use urlencoded body for get token request

This commit is contained in:
Evan Fiordeliso 2024-03-07 18:44:01 -05:00
parent 98d925636c
commit 8bbafd2ee7
1 changed files with 3 additions and 9 deletions

View File

@ -2,8 +2,8 @@ package auth
import (
"encoding/json"
"log/slog"
"net/http"
"strings"
"time"
"github.com/google/go-querystring/query"
@ -52,20 +52,14 @@ func GetToken(params *GetTokenParams) (*Token, error) {
return nil, err
}
res, err := http.Get(TokenUrl + "?" + v.Encode())
res, err := http.Post(TokenUrl, "application/x-www-form-urlencoded", strings.NewReader(v.Encode()))
if err != nil {
return nil, err
}
defer res.Body.Close()
body := make([]byte, res.ContentLength)
if _, err := res.Body.Read(body); err != nil {
return nil, err
}
var token Token
if err := json.Unmarshal(body, &token); err != nil {
slog.Debug("failed to decode token", slog.Any("error", err), slog.String("body", string(body)))
if err := json.NewDecoder(res.Body).Decode(&token); err != nil {
return nil, err
}