This example covers a way to create and maintain an app access token in NodeJS. And store that app access token in Redis to maintain/recover it between restarts and for use in other programs running on the same server.
It's written roughly like a node module
This example uses fetch that is inbuilt into Node 18/19+. But you can easily drop in node-fetch
- Open
.env.samplein a text editor - Visit Twitch Dev Console
- Visit Applications
- Manage your Application, or create one if you don't have one
- Copy the Client ID into the
""ofclient_id - Hit
New Secretand then Ok - Then copy the now Displayed Client Secret into the
""ofclient_secret - Save your modified file as
.env
In a console/terminal, run these commands:
npm installnode run.js
The Redis storage is using a hash key, so access tokens are stored in a hash called twitch_auth and a key called twitch_client_credentials_ and appending the ClientID, so you can feasiably store multiple app access tokens for different client ID's in the same Redis hash. If for example your Server serves multiple Extensions or Twitch Applications.