@@ -118,13 +118,14 @@ func (c *clientCredentialsHook) AfterError(ctx AfterErrorContext, res *http.Resp
118
118
}
119
119
120
120
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
+ }
125
126
126
127
if len (scopes ) > 0 {
127
- values . Set ( "scope" , strings .Join (scopes , " " ) )
128
+ payload [ "scope" ] = strings .Join (scopes , " " )
128
129
}
129
130
130
131
tokenURL := credentials .TokenURL
@@ -139,12 +140,14 @@ func (c *clientCredentialsHook) doTokenRequest(ctx HookContext, credentials *cre
139
140
}
140
141
}
141
142
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 ))
143
146
if err != nil {
144
147
return nil , fmt .Errorf ("failed to create token request: %w" , err )
145
148
}
146
149
147
- req .Header .Set ("Content-Type" , "application/x-www-form-urlencoded " )
150
+ req .Header .Set ("Content-Type" , "application/json " )
148
151
149
152
res , err := c .client .Do (req )
150
153
if err != nil {
0 commit comments