Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including fastify-twitch-ebs-tools with all npm packages installed. Try it out:

var fastifyTwitchEbsTools = require("fastify-twitch-ebs-tools")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

fastify-twitch-ebs-tools v1.0.2

Fastify plugin that provides useful functions for Twitch Extension Backend Services (EBS)

fastify-twitch-ebs-tools

npm (latest) 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.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free