Code Monkey home page Code Monkey logo

twitch-integrity's Introduction

Twitch GQL Integrity Generator

Simplifies the process of obtaining the integrity token for Twitch's GraphQL API.

Do not use this currently

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!

Getting Started

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);
}

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"
}

Example Usage

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",
        ...
    },
});

Example Usage utilizing any http.Agent

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
});

Documentation

twitchIntegrity.getIntegrity()

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
}

twitchIntegrity.getIntegrity(token, agent)

  • token - Twitch OAuth token
  • agent - 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"
}

twitchIntegrity.getIntegrity(token, agent, deviceId)

  • token - Twitch OAuth token
  • agent - Optional http.Agent to use for the request
  • deviceId - 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"
}

twitchIntegrity.getIntegrity(token, agent, deviceId, userAgent)

  • token - Twitch OAuth token
  • agent - Optional http.Agent to use for the request
  • deviceId - Optional device id to use for the request
  • userAgent - 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"
}

twitch-integrity's People

Contributors

kappador avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

kizuno18

twitch-integrity's Issues

any working examples when using the token?

I found this repo after figuring out how to obtain the integrity token myself but i still get failed integrity check error when i try to do a mutation query (have not tested a normal query that requires the header).
have i done something wrong or are you seeing the same issue?
from what i can tell we are both obtaining the token the same way so unless im missing something obvious im not sure why it isnt working for me

Edit: actually just tried adding the X-Device-Id header and it passes the check now, seems to be required

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.