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 🙏

© 2026 – Pkg Stats / Ryan Hefner

disauth

v1.1.0

Published

Discord authentication library for Node.js applications using OAuth2.

Downloads

121

Readme

disauth

Modern Discord OAuth made simple. disauth wraps the Discord OAuth2 and REST APIs with safe defaults, PKCE helpers, and rich typings so you can add login flows to bots, dashboards, and tooling faster.

Features

  • OAuth2 Authorization Code, PKCE, Refresh, and Client Credentials flows
  • Helpers for fetching /users/@me, guilds, and linked connections
  • Configurable base URLs for Discord API proxies
  • Token revocation support and typed error classes
  • Tiny surface area: one configurable Client, plus utilities like generatePkcePair

Installation

pnpm add disauth
# or
npm install disauth
# or
yarn add disauth
# or
bun add disauth

Quick Start

import { Client } from "disauth";

const client = new Client({
  clientId: process.env.DISCORD_CLIENT_ID!,
  clientSecret: process.env.DISCORD_CLIENT_SECRET!,
  redirectUri: "https://your-app.dev/oauth/callback",
  scopes: ["identify", "email"],
});

// 1. Redirect users to Discord
const authUrl = client.generateAuthUrl("state-token");

// 2. Exchange the authorization code in your OAuth callback handler
const { access_token, refresh_token } = await client.exchangeCode(code);

// 3. Call Discord APIs on behalf of the user
const user = await client.getUser(access_token);

Using PKCE

PKCE is pre-baked: generate a verifier/challenge pair on the client, send the challenge with the authorization URL, and later pass the verifier when exchanging the code.

import { Client, generatePkcePair } from "disauth";

const pkce = generatePkcePair();

const authUrl = client.generateAuthUrl({
  state: "csrf-token",
  codeChallenge: pkce.challenge,
  codeChallengeMethod: pkce.method,
});

// Later in the callback route
const tokens = await client.exchangeCode(code, pkce.verifier);

Client Credentials Flow

const tokens = await client.exchangeClientCredentials([
  "applications.commands",
]);

Generic REST Helper

const guilds = await client.api("/users/@me/guilds", access_token);

Pass a full URL to hit custom endpoints or proxies. Headers and request options can be overridden via the third parameter.

Token Revocation

await client.revokeToken(refresh_token, { tokenTypeHint: "refresh_token" });

Error Handling

Errors thrown by the client extend DiscordHttpError. OAuth-specific issues raise DiscordOAuthError with the raw payload attached.

import { DiscordOAuthError } from "disauth";

try {
  await client.exchangeCode(code);
} catch (error) {
  if (error instanceof DiscordOAuthError) {
    console.error(error.error, error.description);
  }
}

Types and Constants

The package exports the complete list of scopes (DISCORD_OAUTH_SCOPES), prompt types, connection and guild interfaces, and Discord endpoints for convenience.