package apiclient import ( "context" "encoding/json" "net/http" "net/url" "strings" "github.com/AFASystems/presence/internal/pkg/config" ) type response struct { Token string `json:"access_token"` } func GetToken(ctx context.Context, cfg *config.Config, client *http.Client) (string, error) { formData := url.Values{} formData.Set("grant_type", "password") formData.Set("client_id", "Fastapi") formData.Set("client_secret", "wojuoB7Z5xhlPFrF2lIxJSSdVHCApEgC") formData.Set("username", "core") formData.Set("password", "C0r3_us3r_Cr3d3nt14ls") formData.Set("audience", "Fastapi") req, err := http.NewRequest("POST", "https://10.251.0.30:10002/realms/API.Server.local/protocol/openid-connect/token", strings.NewReader(formData.Encode())) if err != nil { return "", err } req.Header.Add("Content-Type", "application/x-www-form-urlencoded") req = req.WithContext(ctx) res, err := client.Do(req) if err != nil { return "", err } var j response if err := json.NewDecoder(res.Body).Decode(&j); err != nil { return "", err } return j.Token, nil }