Skip to content

Commit 92cb0ea

Browse files
Amit91848Udit-takkar
andauthoredJun 21, 2024
fix: Webex app not working (#15485)
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
1 parent 3db4888 commit 92cb0ea

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed
 

‎packages/app-store/webex/api/callback.ts

+20-14
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,29 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
1515
/** @link https://developer.webex.com/docs/integrations#getting-an-access-token **/
1616

1717
const redirectUri = encodeURI(`${WEBAPP_URL}/api/integrations/${config.slug}/callback`);
18-
const authHeader = `Basic ${Buffer.from(`${client_id}:${client_secret}`).toString("base64")}`;
19-
const result = await fetch(
20-
`https://webexapis.com/v1/access_token?grant_type=authorization_code&client_id=${client_id}&client_secret=${client_secret}&code=${code}&redirect_uri=${redirectUri}`,
21-
{
22-
method: "POST",
23-
headers: {
24-
Authorization: authHeader,
25-
"Content-Type": "application/x-www-form-urlencoded",
26-
},
27-
}
28-
);
18+
const params = new URLSearchParams([
19+
["grant_type", "authorization_code"],
20+
["client_id", client_id],
21+
["client_secret", client_secret],
22+
["code", code as string],
23+
["redirect_uri", redirectUri],
24+
]);
25+
26+
const options = {
27+
method: "POST",
28+
headers: {
29+
"Content-type": "application/x-www-form-urlencoded",
30+
},
31+
body: params,
32+
};
33+
34+
const result = await fetch("https://webexapis.com/v1/access_token", options);
2935

3036
if (result.status !== 200) {
3137
let errorMessage = "Something is wrong with Webex API";
3238
try {
3339
const responseBody = await result.json();
34-
errorMessage = responseBody.error;
40+
errorMessage = responseBody.message;
3541
} catch (e) {}
3642

3743
res.status(400).json({ message: errorMessage });
@@ -40,8 +46,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
4046

4147
const responseBody = await result.json();
4248

43-
if (responseBody.error) {
44-
res.status(400).json({ message: responseBody.error });
49+
if (responseBody.message) {
50+
res.status(400).json({ message: responseBody.message });
4551
return;
4652
}
4753

0 commit comments

Comments
 (0)