Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!