Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda