/twitch-api-proxy

A Reverse Proxy handling Authentication for the Twitch Helix API

Primary LanguageTypeScript

twitch-api-proxy

A simple API Reverse Proxy for the Twitch Helix API.

It helps by handling the OAuth flow necessary to access the Twitch API. You can then call http://localhost:6776/helix/<endpoint> and access token renewal and necessary Headers for the Requests will be handled by this Proxy.

I'm using this Proxy for example to create Twitch Polls from my Elgato Stream Deck by using the Web Requests Plugin for my Stream Deck because there is no plugin to do that:

Stream Deck HTTP Request Example

Features

  • Brings a webserver that handles the Authorization code grant flow with Twitch
  • Proxies all requests to http://localhost/helix/<endpoint> to Twitch API making sure to refresh your access token if necessary

Usage

Go to the Releases page and download the Binary for your architecture.

Create an application

Go to the Twitch Developer Console and create a new app.

  • Chose a name
  • Set OAuth Redirect URLs to http://localhost:6776/oauth2/redirect
  • Chose Category Broadcaster Suite
  • Chose Client Type Private

You will then get a client-id and a client-secret after clicking on New Secret. Those are necessary when starting the Proxy for the first time.

Run it

Run

$ ./twitch-api-proxy

This will ask for your client-id and client-secret from your Twitch API Application and for your username.

After that, your Browser will open and forward you to Twitch's OAuth page. All Scopes are selected so you can call every API via this Proxy. This is secure because the Authorization Tokens that are being generated are only kept in your local twitch-api-proxy config.

If twitch Proxy shows Logged in successfully! everything is set up correctly!

Send a Request

Have a look at the Twitch API Reference for Endpoints you can use.

If the Endpoint is for example PATCH https://api.twitch.tv/helix/channels, send a PATCH Request to http://localhost:6776/helix/channels and the necessary Headers for Authorization will be added to your Request automatically.

Do not add any extra headers (eg. Authorization or Client-Id). All headers sent with your request will be removed. All Methods other than GET will automatically get the Content-Type: application/json header.

Reset twitch-api-proxy

If you need to reset your config for twitch-api-proxy for any reason, go to your Users Home Directory and then .config/twitch-api-proxy/. There is a config.json file - if you delete it an then re-run twitch-api-proxy, it will ask for your Credentials like on first run.

If you have any other problems, please make sure to create an Issue including your twitch-api-proxy.log file.

Developers

Committing

Make sure to follow the Conventional Commits Format when committing.

This Workspaces recommends installing Conventional Commits Add-On for VS-Code. After installation use CMD+Shift+P / Ctrl+Shift+P and run Conventional Commits. Normal commits will not be accepted and Releasing will fail if no Conventional Commit was used.

Install

Make sure you have bun installed on your machine.

To install dependencies:

$ bun install

Run

To run the Proxy:

$ bun run start

Build

To build a compiled binary:

$ bun run build

Development

To run the Proxy with hot reload in development:

$ bun run dev

Release

Create a new Git Tag and push it

$ git tag vX.X.X
$ git push origin vX.X.X

This will run the GitHub Action to create a new Release automatically.