Simplifies the process of obtaining the integrity token for Twitch's GraphQL API.
Twitch has implemented another security update, which flags the tokens generated by this package as a bot. Please wait until i update this package before you use it again!
Install the module with: npm install twitch-integrity
const twitchIntegrity = require('twitch-integrity');
let token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
let integrity;
try {
integrity = await twitchIntegrity.getIntegrity(token);
} catch (e) {
console.log(e);
}
{
"error": false,
"token": "v4.public.e30=",
"device": "289b553fe214137b",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
"oauth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
const needle = require('needle');
const twitchIntegrity = require('twitch-integrity');
let token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
let integrity;
try {
integrity = await twitchIntegrity.getIntegrity(token);
} catch (e) {
console.log(e);
}
needle("post", "https://gql.twitch.tv/gql", {
"operationName": "FollowButton_FollowUser",
"variables": {
"input": {
"targetID": "655929360",
"disableNotifications": false
}
},
"extensions": {
"persistedQuery": {
"version": 1,
"sha256Hash": "51956f0c469f54e60211ea4e6a34b597d45c1c37b9664d4b62096a1ac03be9e6"
}
}
}, {
headers: {
...
"Client-Integrity": integrity.token,
"Authorization": "OAuth " + integrity.oauth, // I am using the oauth token from the result, it ensures that the correct oauth token is used
"Client-ID": "kimne78kx3ncx6brgo4mv6wki5h1ko",
...
},
});
const needle = require('needle');
const twitchIntegrity = require('twitch-integrity');
const proxyAgent = require('proxy-agent');
let token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
let agent = new proxyAgent("http://your.proxy:port");
let integrity = await twitchIntegrity.getIntegrity(token, agent);
needle("post", "https://gql.twitch.tv/gql", {
"operationName": "FollowButton_FollowUser",
"variables": {
"input": {
"targetID": "655929360",
"disableNotifications": false
}
},
"extensions": {
"persistedQuery": {
"version": 1,
"sha256Hash": "51956f0c469f54e60211ea4e6a34b597d45c1c37b9664d4b62096a1ac03be9e6"
}
}
}, {
headers: {
...
"Client-Integrity": integrity.token,
"Authorization": "OAuth " + integrity.oauth, // I am using the oauth token from the result, it ensures that the correct oauth token is used
"Client-ID": "kimne78kx3ncx6brgo4mv6wki5h1ko",
...
},
agent: agent
});
Generates an anonymous integrity token
Example Result:
{
"error": false,
"token": "v4.public.e30=",
"device": "289b553fe214137b",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
"oauth": null
}
token
- Twitch OAuth tokenagent
- Optional http.Agent to use for the request
Example Result:
{
"error": false,
"token": "v4.public.e30=",
"device": "289b553fe214137b",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
"oauth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
token
- Twitch OAuth tokenagent
- Optional http.Agent to use for the requestdeviceId
- Optional device id to use for the request
Example Result:
{
"error": false,
"token": "v4.public.e30=",
"device": "289b553fe214137b",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
"oauth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
token
- Twitch OAuth tokenagent
- Optional http.Agent to use for the requestdeviceId
- Optional device id to use for the requestuserAgent
- Optional user agent to use for the request
Example Result:
{
"error": false,
"token": "v4.public.e30=",
"device": "289b553fe214137b",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
"oauth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}