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

@oauth-everything/passport-discord

v1.0.2

Published

Discord OAuth 2.0 strategy for Passport.js

Downloads

1,594

Readme

@oauth-everything/passport-discord

Version Dependencies Dev Dependencies Vulnerabilities License Types

A fully typed Passport strategy for authenticating users with Discord using OAuth 2.0 and the Discord API.

Passport is authentication middleware for Node.js. It allows you to easily add user authentication to your application. It supports any application using Connect-style middleware, including Express.

@oauth-everything/passport-discord is an authentication Strategy for Passport that allows users to authenticate using their Discord account.

Installation

$ npm install @oauth-everything/passport-discord

Setup/Configuration

import express from 'express';
import passport from 'passport';

// Import the strategy and types from @oauth-everything/passport-discord
import { Strategy, Profile, VerifyCallback /*, Scope*/ } from '@oauth-everything/passport-discord';

// Set up express/connect/etc
const app = express();
app.use(...);
...
...

// Set up passport
passport.serializeUser((user: User, done) => {
    done(null, /* user.id */);
})
passport.deserializeUser((id: string, done) => {
    done(null, /* database.getUserById(id) */);
});
...
...

// Set up the Discord Strategy
passport.use(new Strategy(
    {
        // The Client Id for your discord application (See "Discord Application Setup")
        clientID: "wumpus",

        // The Client Secret for your discord application (See "Discord Application Setup")
        clientSecret: "supmuw",

        // The callback URL - Your app should be accessible on this domain. You can use
        // localhost for testing, just makes sure it's set as a Redirect URL (See "Discord Application Setup")
        callbackURL: "https://myapp.com/auth/discord/callback",

        /* Optional items: */

        // The scope for your OAuth request - You can use strings or Scope values
        // The default scope is Scope.IDENTIFY which gives basic profile information
        scope: [Scope.EMAIL, Scope.GUILDS_JOIN, "webhook.incoming", ...]

    },
    (accessToken: string, refreshToken: string, profile: Profile, cb: VerifyCallback<User>) => {

        // `profile` will be the user's Discord profile
        console.log(profile);

        // You should use that to create or update their info in your database/etc and then return the user using `cb`
        cb(null, /* database.createOrUpdateDiscordUser(profile) */)

    }
));

// Connect passport to express/connect/etc
app.get("/auth/discord", passport.authenticate("discord"));
app.get("/auth/discord/callback", passport.authenticate("discord", {
    failureRedirect: "/login",
    successRedirect: "/"
}));

// Start the app
app.listen(80);
const express = require('express');
const passport = require('passport');

// Import the strategy from @oauth-everything/passport-discord
const { Strategy /*, Scope*/ } = require('@oauth-everything/passport-discord');

// Set up express/connect/etc
const app = express();
app.use(...);
...
...

// Set up passport
passport.serializeUser((user, done) => {
    done(null, /* user.id */);
})
passport.deserializeUser((id, done) => {
    done(null, /* database.getUserById(id) */);
});
...
...

// Set up the Discord Strategy
passport.use(new Strategy(
    {
        // The Client Id for your discord application (See "Discord Application Setup")
        clientID: "wumpus",

        // The Client Secret for your discord application (See "Discord Application Setup")
        clientSecret: "supmuw",

        // The callback URL - Your app should be accessible on this domain. You can use
        // localhost for testing, just makes sure it's set as a Redirect URL (See "Discord Application Setup")
        callbackURL: "https://myapp.com/auth/discord/callback",

        /* Optional items: */

        // The scope for your OAuth request - You can use strings or Scope values
        // The default scope is Scope.IDENTIFY which gives basic profile information
        scope: [Scope.EMAIL, Scope.GUILDS_JOIN, "webhook.incoming", ...]

    },
    (accessToken, refreshToken, profile, cb) => {

        // `profile` will be the user's Discord profile
        console.log(profile);

        // You should use that to create or update their info in your database/etc and then return the user using `cb`
        cb(null, /* database.createOrUpdateDiscordUser(profile) */)

    }
));

// Connect passport to express/connect/etc
app.get("/auth/discord", passport.authenticate("discord"));
app.get("/auth/discord/callback", passport.authenticate("discord", {
    failureRedirect: "/login",
    successRedirect: "/"
}));

// Start the app
app.listen(80);

Discord Application Setup

  1. Go to https://discordapp.com/developers/applications and create a New Application

    asdf asdf

  2. Copy the Client ID and Client Secret and save them somewhere safe

    asdf

  3. Go to the OAuth tab and add a redirect URL - this will be the URL on your website where Passport is set up

    asdf asdf

License

The MPL v2 License