npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

twitch-node-auth-provider

v0.1.0

Published

Obtain auth tokens for Twitch using an Node HTTP server popup.

Downloads

3

Readme

Twitch.js - Node (HTTP) auth provider

This is an AuthProvider implementation for d-fischer twitch package family that will automatically pop up a Twitch OAuth dialog in default user browser as soon as new scopes are requested.

Installation

To add this library to your project, just execute:

yarn add twitch-node-auth-provider

or using npm:

npm install twitch-node-auth-provider

Basic usage

To instantiate an ApiClient with this auth provider, just pass it to its constructor:

import { ApiClient } from "twitch";
import { NodeAuthProvider } from "twitch-node-auth-provider";

const authProvider = new NodeAuthProvider({
  clientId: "7m7uv94xk5lu42H2G27ay7nd1rpg",
  redirectUri: "http://localhost:4242/auth",
});

const client = new ApiClient({
  authProvider,
});

client.helix.users.getMe(true);

Options

| name | type | optional | description | | ----------- | ----------------------------------------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------- | | clientId | string | false | The client ID found in your Twitch Dev Console. | | redirectUri | string | false | The redirect URI you provided in your Twitch Dev Console. | | scopes | string \| string[] | true | A list of scopes that will always be requested. | | accessToken | AccessToken | true | Represents the data of an OAuth access token returned by Twitch. |

Force verify

To allow the user to "log out" and change to another account, use enableForceVerify():

(async () => {
  await client.helix.users.getMe(); // <- open login page
  await client.helix.users.getMe(); // <- already logged-in

  authProvider.enableForceVerify(); // <- force login for all the latter calls.

  await client.helix.users.getMe(); // <- open login page
  await client.helix.users.getMe(); // <- open login page
  authProvider.enableForceVerify(true); // <- force login on the next call only.

  await client.helix.users.getMe(); // <- open login page
  await client.helix.users.getMe(); // <- already logged-in
})();

Events

Listen all events:

authProvider.server.on("event", ({ eventName, data }) =>
  console.log(eventName, data)
);

Or listen one event:

authProvider.server.on("BROWSER_OPEN", () =>
  console.log("Opened Twitch login page in your default browser, take a look!")
);

Events list

  • ERROR
  • CLOSE
  • LISTEN
  • LISTENING
  • BROWSER_OPEN
  • ACCESS_TOKEN

Error types

  • UNKNOW
  • INVALIDATED
  • LOGIN_TIMEOUT
  • INVALID_STATE
  • ACCESS_DENIED