Https://id.twitch.tv/oauth2/authorize res.body returns HTML

getPubSubToken(process.env.GET_TOKEN, (res) => {

  console.log('Token Res', res);

  PST = res.body.access_token;

  twitchWebSocketConnect(PST);

  return PST; 

})

function twitchWebSocketConnect(PST){

  console.log('Starting Twitch WebSocket');

  ws = new WebSocket('wss://pubsub-edge.twitch.tv'); 

  ws.onopen = function(event) {

      console.log('Websocket Open');

      validateTwitchToken(PST);

      listenPubSub(PST);

  };

  ws.onerror = function(error) {

      console.log('Websocket Error', error);

  };

  ws.onmessage = function(event) {

      message = JSON.parse(event.data);

      console.log('Websocket Message', message);

      if (message.type == 'RECONNECT') {

          console.log('Websocket Reconnecting...');

          // setTimeout(connect, reconnectInterval);

      }

  };

  ws.onclose = function() {

    console.log('Websocket Closed');

      console.log('Websocket Reconnecting');

      // setTimeout(twitchWebSocketConnect(), 1000);

  };

}

const getPubSubToken = (callback) => {

  const options = { 

    url: 'https://id.twitch.tv/oauth2/authorize',

    json: true,

    body: { 

      client_id: process.env.TWITCH_CLIENT_ID,

      redirect_uri:'http://localhost',

      response_type:'code',

      scope: 'channel:read:redemptions'

    }

  };

  request.get(options, (err,res,body) => {

    if(err) {

      return console.log('Token Error', err);

    }

    if(callback) {

      callback(res);

    }

  });

}

Correct

Step one of oAuth is to redirect the user to Twitch.

It’s not a thing you request.get

NodeJS example for it