GithubHelp home page GithubHelp logo

barrycarlyon / twitch_profile_extension Goto Github PK

View Code? Open in Web Editor NEW
23.0 4.0 3.0 560 KB

A simple Twitch Extension to cover the basics of using the JWT and EBS together to get Twitch API information

License: Do What The F*ck You Want To Public License

JavaScript 88.08% HTML 6.65% CSS 5.26%

twitch_profile_extension's Introduction

Whats in this Repo

This Repo provides a simple example of a Twitch Extension.

The Example EBS is written in NodeJS

This Twitch Extension primarilly demonstrates the following

Front End

  • Theme Switching based on the Twitch Theme toggle
  • Prompting a user to Share their Twitch ID with the Extenion
  • Making a call to a EBS and display the result

Back End

A Twitch Extension Back end is also known as an "EBS" or "Extension Backend Service"

  • Generating an App Access Token for the EBS to use
  • Parsing a JWT Token that was passed up from the front end
  • Calling the Twitch API from the EBS

Note: this EBS expects node.js 18 as it utilises fetch built into node.js 18

What this extension/guide/example doesn't do is cover SSL hosting. EITHER FOR TESTING OR YOUR EBS

So without SSL on your frontend/EBS browsers will usually block access on mixed content grounds.

Example Images

Awaiting Share Shared ID EBS Server Log

Getting Started.

This covers how to get started if you don't already have an extension setup.

If you already do you can just use your existing hosting/test solution and use the existing Extension. And follow from step 12 for the relevant keys/IDs/secrets

  1. Visit the Twitch Dev Console to create a new extension. Link
  2. Give it a Name, you cannot use "Extension," "Twitch," or "Glitch". Hit Continue
  3. Select the Panel checkbox, leave the reset as is. Hit Create
  4. Select Capabilities at the top
  5. Select Yes, I would like my extension to request an identity link. and Save Changes
  6. Select Asset Hosting at the top
  7. Change Panel Viewer Path to index.html
  8. Change the Panel Height to 500 and Save Changes
  9. Top right hit Extension Settings
  10. In the ebs folder copy config_sample.json to config.json
  11. Change the port as need
  12. Copy the clientID from this page, it's at the top, into the "" of client_id in config.json
  13. Under Twitch API Client Secret Click on Generate Secret
  14. Hit OK
  15. Copy the now shown Client Secret into the "" of client_secret in config.json
  16. Under "Extension Secrets" on the page hit the "show" button
  17. Copy the now shown key (including any = on the end) into the "" of extension_secret in config.json
  18. Run by cd to your ebs folder and run the commands
  19. npm install
  20. node .
  21. In extension copy config_sample.js to config.js
  22. Change the https://theURLtoMyEBS to the URL of your now running EBS

For easy "what key goes where" see this image.

What Key goes where

FINALLY

Install the Extension to your channel and test it.

Notes

These instructions do not cover SSL termination, which is the only gotcha here.

You can use something like NGROK for testing.

You'd need two tunnels, one for your frontend and one for your backend (or if you know what you are doing just the one). And to adjust the Extension Console settings (and config.json's) as needed.

Personally I use NGINX to SSL Terminate, and a reverse SSL tunnel to get traffic from my production server to my local machine.

GOTCHAS

The EBS for this server, generates an App Access Token at Boot, but doesn't test it/renew it. So if you use this code for a production EBS it'll probably stop working after 60 days. The EBS is for short demonstrations of the code flow.

CSP

If you are testing this example in Hosted Test or above, you'll need to add your EBS URL to the CSP fields, specifically the Allowlist for URL Fetching Domains

You can find those at -> Dev Console -> Manage an Extension -> Manage a Version -> Capabilties

image

See also the Documentation on Content Restrictions

twitch_profile_extension's People

Contributors

barrycarlyon avatar dependabot[bot] avatar

Stargazers

altaev avatar Andrew J. Kramer avatar Trung Hoang avatar Nadim avatar  avatar PSingletary avatar Julian Paule avatar  avatar Christophe Dri avatar  avatar  avatar Paulo Valadares avatar  avatar Vitaliy Zakutniy avatar Ankit Kumar Pal avatar Lam avatar Derrick avatar Martin Giger avatar LE avatar  avatar Evan Cloutier avatar Roxanne Garcia avatar  avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

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.