Skip to content
Fastify plugin that provides useful functions for Twitch Extension Backend Services (EBS)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
appveyor.yml
index.d.ts
index.js
index.test.js
jest.config.js
package-lock.json
package.json
tsconfig.json

README.md

fastify-twitch-ebs-tools

npm (tag) Travis Build Status AppVeyor Build Status Maintainability Test Coverage Greenkeeper badge

Fastify plugin providing useful functions for Twitch Extension Backend Services (EBS). Internally it uses twitch-ebs-tools.

Installation

npm install --save fastify-twitch-ebs-tools

Usage

Register as a plugin to get access to additional methods.

Example below assumes Twitch token to be sent via request headers.

const fastify = require('fastify');

fastify.register(require('fastify-twitch-ebs-tools'), {
  secret: 'twitch shared secret',
  disabled: false,
});

fastify.get('/config/:channelId', (req, reply) => {
  const { token } = req.headers;
  const { channelId } = req.params;
  const valid = fastify.twitchEbs.validatePermission(
    token,
    channelId,
    'broadcaster',
  );

  if (valid) {
    // do something and send the reply back
    reply.send(/* reply object */);
  } else {
    // error 400
  }
});

fastify.listen(3000, (error) => {
  if (error) throw error;
});

Options

  • secret - Twitch shared secret used to sign and verify JWTs (required). The plugin will throw an error if no secret is provided. Required.

  • disabled - if true, all validation methods will return true. Useful for temporarily disabling route authentication for debugging purposes. Does not affect validateToken() method. Defaults to false. Optional.

Usage

All plugin methods pass arguments to relevant methods of twitch-ebs-tools. Refer to twitch-ebs-tools documentation to get more details.

Available methods:

License

Licensed under MIT License. See LICENSE for more information.

You can’t perform that action at this time.