Status 400 - Missing Client id when refreshing User token with grantType=refresh_token[on Postman it works]]

Hello dear developers,
im coming to a problem that i cant resolve on my own. Im sure that its only a quick look for you guys to see my error. But as far as i understood the whole process…i dont quite get my mistake here lol.Im pretty sure that im not trying to refresh an App token either and ID token.

Some background Infos:
i requested the access token by redirecting the user to the auth Site of Twitch so i get the token with a specified Scope.

Fun Fact…this request worked with postman, but not with Axios im using on node… does anyone of you have an idea?
my Node code looks like this:

  function whatEver() {

  axios({
    method: 'POST',
    url: "https://id.twitch.tv/oauth2/token",
    headers: {
//tried the Postman Header Settings
      'Content-Type': 'application/x-www-form-urlencoded',
      Accept: "*/*",
      "Accept-Encoding": "gzip, deflate, br",
      Connection: "keep-alive"
      //'Accept': 'application/json'
    },
    data: {
      grant_type: "refresh_token",
      refresh_token: >refreshToken>,
      client_id: <AppClientID>,
      client_secret: <APPCLIENTSECRET>
    }
  }).catch(result => console.log(result))
}

result is:

response: {
    status: 400,
    statusText: 'Bad Request',
    headers: {
      date: 'Sun, 14 Jun 2020 20:26:19 GMT',
      'content-type': 'application/json',
      'content-length': '45',
      connection: 'keep-alive',
      server: 'nginx/1.14.1',
      'access-control-allow-origin': '*',
      'x-ctxlog-logid': '1-5ee687eb-a34e3a20aa2f38f07b7f3110'
    },
    config: {
      url: 'https://id.twitch.tv/oauth2/token',
      method: 'post',
      data: '{"grant_type":"refresh_token","refresh_token":"","client_id":"","client_secret":""}', //I just blanked all the keys etc out...dont wonter this is empty here
      headers: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      validateStatus: [Function: validateStatus]
    },
    request: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      connection: [TLSSocket],
      _header: 'POST /oauth2/token HTTP/1.1\r\n' +
        'Accept: */*\r\n' +
        'Content-Type: application/x-www-form-urlencoded\r\n' +
        'Accept-Encoding: gzip, deflate, br\r\n' +
        'Connection: keep-alive\r\n' +
        'User-Agent: axios/0.19.2\r\n' +
        'Content-Length: 193\r\n' +
        'Host: id.twitch.tv\r\n' +
        '\r\n',
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      insecureHTTPParser: undefined,
      path: '/oauth2/token',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: { status: 400, message: 'missing client id' }
  },
  isAxiosError: true,
  toJSON: [Function]

Thanks to all the people that try to help me here. Im just got stuck…i might be blind here… :confused:

here is my Postman result:
Header Setup

Body Setup

I found the error… its somehow Axios or the fact that i didnt encode as needed… dont know… it worked for two ways…

Way 1:

    function testFetch() {
      let body = new FormData();
      body.append("grant_type", "refresh_token")
      body.append("refresh_token", testlol)
      body.append("client_id", TWITCH_CLIENT_ID)
      body.append("client_secret", TWITCH_SECRET)
      fetch("https://id.twitch.tv/oauth2/token", {

        method: 'POST',
        headers: {
          //tried the Postman Header Settings
          //'Content-Type': 'application/x-www-form-urlencoded',
          Accept: "*/*",
          "Accept-Encoding": "gzip, deflate, br",
          Connection: "keep-alive"
          //'Accept': 'application/json'
        },
        body: body,
      }).then(async res => console.log(res, await res.json())).catch(async res => console.log(res, await res.json()))
        }
  1. Way:

     function test1212() {
       const details = {
         grant_type: "refresh_token",
         refresh_token: testlol,
         client_id: TWITCH_CLIENT_ID,
         client_secret: TWITCH_SECRET
    
       }
    
       let formBody  = []
    
       for (var property in details) {
         var encodedKey = encodeURIComponent(property);
         var encodedValue = encodeURIComponent(details[property]);
    
         formBody.push(encodedKey + "=" + encodedValue);
    
       }
    
       formBody = formBody.join("&");
    
       axios({
         method: 'POST',
         url: "https://id.twitch.tv/oauth2/token",
         headers: {
           //"Authorization": "OAuth " + lol,
           'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
           Accept: "*/*",
           "Accept-Encoding": "gzip, deflate, br",
           Connection: "keep-alive"
           //'Accept': 'application/json'
         },
    
         data: formBody
    
       }
    
       ).then(result => console.log(result)).catch(result => console.log(result))
    
     }
    

Post can be closed now!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.