/go-twitch-ext

A library to help with the development of an EBS for Twitch Extensions

Primary LanguageGoMIT LicenseMIT

go-twitch-ext

GoDoc Build Status Go Report Card codecov GitHub Release

A library to help with the development of an EBS for a Twitch Extension

For any help please consult FAQ section

Supported Endpoints & Features

Features:

Twitch JWT

  • Twitch Claims structure supported
  • Sign Twitch claims into JWT Tokens
  • Verify Client/EBS Created Twitch JWT tokens into claims obj

API Endpoint:

This package supports the following Twitch Extension API endpoints

  • Get Live Channels with Extension Activated
  • Create Extension Secret
  • Get Extension Secret
  • Revoke Extension Secrets
  • Set Extension Required Configuration
  • Set Extension Configuration Segment
  • Get Extension Channel Configuration
  • Get Extension Configuration Segment
  • Send Extension PubSub Message
  • Send Extension Chat Message

Installing

go get github.com/jackmcguire1/go-twitch-ext

Example

package main

import (
	"log"
	"os"

	twitch "github.com/jackmcguire1/go-twitch-ext"
)

var twitchPkg *twitch.Twitch

func init() {
	twitchPkg = twitch.NewClient(
		os.Getenv("OWNER_ID"),
		os.Getenv("CLIENT_ID"),
		os.Getenv("EXT_SECRET"),
		os.Getenv("EXT_VERSION"),
		os.Getenv("EXT_CONFIG_VER"),
	)
}

func main() {
	claims := twitchPkg.CreateClaims(
		"35851594",
		twitch.BroadcasterRole,
		twitch.FormBroadcastSendPubSubPermissions(),
	)
	token, err := twitchPkg.JWTSign(claims)
	if err != nil {
		log.Fatal(err)
	}

	claims, err = twitchPkg.JWTVerify(token)
	if err != nil {
		log.Fatal(err)
	}
	log.Println(claims)
}

Development

To develop go-twitch-ext or interact with its source code in any meaningful way, be sure you have the following installed:

Prerequisites

You will need to activate Modules for your version of Go, generally by invoking go with the support GO111MODULE=on environment variable set.

Twitch Extension Configuration

From your Twitch Extension Dashboard you can get the following:

  • Client ID
  • Base64 Secret
  • Extension Version
  • Extension (Broadcaster/Developer) Config Version - OPTIONAL

Owner ID

To get the owner ID, you will need to first create a temporary access token via https://twitchtokengenerator.com/
Next fetch your ownerID from a simple CURL command against the Twitch /users endpoint.
You'll also need the client ID from https://twitchtokengenerator.com/ as part of the query.

curl -H "Client-ID: <client id>" -H "Authorization: Bearer <access token>" -X GET "https://api.twitch.tv/helix/users?login=<twitch-login-name>"

your ownerID is the value of 'id'

{
	"data": [{
		"id": "35851594",
		"login": "crazyjack12",
		"display_name": "crazyjack12",
		"type": "",
		"broadcaster_type": "",
		"description": "Do What Thou Wilt",
		"profile_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/ea0bf955-255a-4eca-ad80-460b88162910-profile_image-300x300.png",
		"offline_image_url": "",
		"view_count": 1702
	}]
}

Create your own extension!

Get started and create your extension today!.

FAQ & SUPPORT

For any questions or suggestions please join the 'go-twitch-ext' channel on Discord!

License

The source code for go-twitch-ext is released under the MIT License.

Donations

All donations are appreciated!

Donate