Skip to main content

max / makenotwork

Fix OAuth token exchange: send form-urlencoded per spec The /oauth/token endpoint expects application/x-www-form-urlencoded but the client was sending JSON, causing 415 errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author: Max J. <87768334+MaxJMath@users.noreply.github.com> · 2026-05-11 18:41 UTC
Commit: 90c58597e052b9f13c847cbf8552b3c842add08a
Parent: f1b410b
1 file changed, +8 insertions, -9 deletions
@@ -139,13 +139,13 @@ impl SyncKitClient {
139 139 ) -> Result<(Uuid, Uuid)> {
140 140 let redirect_uri = format!("http://127.0.0.1:{}/", redirect_port);
141 141
142 - let body = Bytes::from(serde_json::to_vec(&OAuthTokenRequest {
143 - grant_type: "authorization_code",
144 - code,
145 - redirect_uri: &redirect_uri,
146 - code_verifier,
147 - client_id: &self.config.api_key,
148 - })?);
142 + let form_params = [
143 + ("grant_type", "authorization_code"),
144 + ("code", code),
145 + ("redirect_uri", &redirect_uri),
146 + ("code_verifier", code_verifier),
147 + ("client_id", &self.config.api_key),
148 + ];
149 149
150 150 // OAuth authorization codes are single-use. Retrying after a
151 151 // network error would send an already-consumed code, producing a
@@ -154,8 +154,7 @@ impl SyncKitClient {
154 154 let resp = check_response(
155 155 self.http
156 156 .post(&self.endpoints.oauth_token)
157 - .header("content-type", "application/json")
158 - .body(body)
157 + .form(&form_params)
159 158 .send()
160 159 .await?,
161 160 )