New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

disauth

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

disauth

Discord authentication library for Node.js applications using OAuth2.

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

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.

Keywords

discord

FAQs

Package last updated on 04 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts