Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

213
Vistas
check a twitch chat token for its validity

I try to check a twitch chat token for its validity and return true or false depending on that. If I ask for an incorrect token, it works, but as soon as I ask for a valid token, I get no value back. I just can't figure out what I'm doing wrong

const tmi = require('tmi.js');
function checkToken(name, token, callback) {
  var errLogs = '';
  const client = new tmi.client({
    identity: {
      username: name,
      password: token
    },
    channels: ['channel']
  });
  client.connect()
    .catch(error => {
      console.log(error)
      if (error) {
        console.log('FAILED')
        errLogs = 'error';
        //return false;
      } else {
        console.log('VALID')
        errLogs = 'valid';
        //return true;
      }
      callback(errLogs);
    })
}
checkToken('username', 'oauth:XXXX...', function(res) {
  if (res) {
    console.log(res + ' TOKEN FAILED')
    ///... token is not Valid
  } else {
    console.log(res + ' TOKEN VALID')
    ///... token is Valid
  }
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To validate a token, you should use the Validate Endpoint instead of tmi.js

So you do the following call

curl -X GET 'https://id.twitch.tv/oauth2/validate'
-H 'Authorization: Bearer '

Don't prefix your token with oauth:

Or for a basicish javascript/fetch call:

            fetch(
                'https://id.twitch.tv/oauth2/validate',
                {
                    "headers": {
                        "Authorization": "Bearer " + access_token
                    }
                }
            )
            .then(resp => resp.json())
            .then(resp => {
                if (resp.status) {
                    if (resp.status == 401) {
                        //'This token is invalid: ' + resp.message;
                        return;
                    }
                    // 'Unexpected output with a status?';
                    return;
                }
                if (resp.client_id) {
                    client_id = resp.client_id;
                    // token is valid was was generated for that client_id
                    return;
                }
                // if got here unexpected output from twitch
            })
            .catch(err => {
                console.log(err);
                // 'An Error Occured loading token data';
            });

See documentation: https://dev.twitch.tv/docs/authentication#validating-requests

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda