From 10d20489752d04a1896508f002ff2ebf8899b09b Mon Sep 17 00:00:00 2001 From: amk-dev Date: Mon, 19 Feb 2024 13:31:05 +0530 Subject: [PATCH] fix: use x-www-form-urlencoded for token exchange requests --- .../hoppscotch-common/src/helpers/oauth.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/hoppscotch-common/src/helpers/oauth.ts b/packages/hoppscotch-common/src/helpers/oauth.ts index 1e4267a2d..7c630d4b1 100644 --- a/packages/hoppscotch-common/src/helpers/oauth.ts +++ b/packages/hoppscotch-common/src/helpers/oauth.ts @@ -250,19 +250,23 @@ const handleOAuthRedirect = async () => { return E.left("NO_CODE_VERIFIER" as const) } + const data = new URLSearchParams({ + grant_type: "authorization_code", + code: queryParams.code, + client_id: clientID, + client_secret: clientSecret, + redirect_uri: redirectUri, + code_verifier: codeVerifier, + }) + // Exchange the authorization code for an access token const tokenResponse = await runRequestThroughInterceptor({ url: tokenEndpoint, - data: JSON.stringify({ - grant_type: "authorization_code", - code: queryParams.code, - client_id: clientID, - client_secret: clientSecret, - redirect_uri: redirectUri, - code_verifier: codeVerifier, - }), + data: data.toString(), method: "POST", - headers: {}, + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, }) // Clean these up since we don't need them anymore