slack error "invalid_code" after sending request to oauth.access url

Viewed 2269

I am trying to authenticate my app with Slack. It was working perfectly fine for a few days, but now it's throwing me an error

invalid_code

const requestBody = qs.stringify({
    code: code,
    redirect_uri: redirect_uri,
    client_id: client_id,
    client_secret: client_secret
  });

  await axios
    .post(url, requestBody, config).
then(server => console.log(server)).catch(err => console.log(err))

Response from server: { ok: false, error: 'invalid_code' }

The code I get is in this format. code=303414024726.805164905556.526d546072e9b2408e0743f42ca3bb5843553a6c3b930b1de2c1e31847b25448

I think this is JWT token but I am not sure.

Any help would be appreciated.

1 Answers

This is how i made it work

 let slackUrl = `https://slack.com/api/oauth.v2.access`;
let client_id = process.env.SLACK_CLIENT_ID;
let client_secret = process.env.SLACK_CLIENT_SECRET;
let details = {
    code,
    client_id,
    client_secret
}
var formBody = [];
for (var property in details) {
    var encodedKey = encodeURIComponent(property);
    var encodedValue = encodeURIComponent(details[property]);
    formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");

const _headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
};

let config = {
    method: 'POST',
    url: slackUrl,
    data: formBody,
    headers: _headers
};

let installation = await axios(config);
Related