Skip to content

Commit b0cc516

Browse files
committed
fix: failure api invoke
1 parent 9d38299 commit b0cc516

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

internal/sdk/internal/hooks/clientcredentials.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,14 @@ func (c *clientCredentialsHook) AfterError(ctx AfterErrorContext, res *http.Resp
118118
}
119119

120120
func (c *clientCredentialsHook) doTokenRequest(ctx HookContext, credentials *credentials, scopes []string) (*session, error) {
121-
values := url.Values{}
122-
values.Set("grant_type", "client_credentials")
123-
values.Set("client_id", credentials.ClientID)
124-
values.Set("client_secret", credentials.ClientSecret)
121+
payload := map[string]string{
122+
"grant_type": "client_credentials",
123+
"client_id": credentials.ClientID,
124+
"client_secret": credentials.ClientSecret,
125+
}
125126

126127
if len(scopes) > 0 {
127-
values.Set("scope", strings.Join(scopes, " "))
128+
payload["scope"] = strings.Join(scopes, " ")
128129
}
129130

130131
tokenURL := credentials.TokenURL
@@ -139,12 +140,14 @@ func (c *clientCredentialsHook) doTokenRequest(ctx HookContext, credentials *cre
139140
}
140141
}
141142

142-
req, err := http.NewRequestWithContext(ctx.Context, http.MethodPost, tokenURL, bytes.NewBufferString(values.Encode()))
143+
jsonPayload, _ := json.Marshal(payload)
144+
145+
req, err := http.NewRequestWithContext(ctx.Context, http.MethodPost, tokenURL, bytes.NewBuffer(jsonPayload))
143146
if err != nil {
144147
return nil, fmt.Errorf("failed to create token request: %w", err)
145148
}
146149

147-
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
150+
req.Header.Set("Content-Type", "application/json")
148151

149152
res, err := c.client.Do(req)
150153
if err != nil {

0 commit comments

Comments
 (0)