401 Error ("Invalid value for 'client_id' parameter.") when hitting /token endpoint

Hi folks,

I am encountering a “Invalid value for ‘client_id’ parameter.” when hitting the /token endpoint of my application from my nodejs backend. My application is configured to use an authorization code, which is what I successfully get back from the /authorize endpoint. I then send that authorization code with the other required params specified in the documentation, along with client_id (which isn’t specified in the docs…but the error implies that it’s needed).

Here is the code for the part of my app that pings the /token endpoint:

async function pingTokenEndpoint(authorizationCode, sessionID) {
  let data = {
    code : authorizationCode,
    grant_type : `authorization_code`,
    client_id : config.clientID,
    client_secret : config.clientSecret,
    redirect_uri : config.callbackURL
  }

  const base64EncodedData = Buffer.from(JSON.stringify(data)).toString('base64');
  console.log({data, config})
  let tokenResponse = await axios.post(config.tokenURL, base64EncodedData, { headers: { 'Authorization' :  'Basic ' + sessionID, 'Content-Type': 'application/x-www-form-urlencoded' } }).then(response => console.log(response)) 

}

Note that I encoded the data in my axios.post request as per another thread I found on this forum, but I experience the error whether I encode the POST payload or not. I also experience the error whether or not I include the session ID in the payload (is it required for the /token endpoint?). I’m at a loss as to what could be the culprit here.

Hi @ct744x ,

You do not have to send back the base64EncodedData, however you are missing the code verifier.

So you should have:

let data = {
code : authorizationCode,
grant_type : authorization_code,
client_id : config.clientID,
client_secret : config.clientSecret,
redirect_uri : config.callbackURL,
code_verifier : verifier
}

As mentioned in:

1 Like

Thank you so much for responding to this! I didn’t realize I had to include that param. I’ll give this a try and update the thread with the results.