passport-discord-auth
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Discord Auth Banner


DiscordGitHub


An updated passport authentication strategy for Discord.

Discord Server NPM Version NPM Downloads Test Status NPM Size


Passport strategy for authenticating with Discord using the OAuth 2.0 API. This library lets you authenticate using Discord in your Node.js applications. By plugging into Passport, Discord authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Note: Feel free to open an issue if you have any questions or need help with anything.

Installation

# Using npm
> npm install passport-discord-auth
# Using yarn or pnpm
> yarn/pnpm add passport-discord-auth

Usage

Importing

This library supports both typescript and javascript, with ES6 modules and CommonJS.

// ES6 modules
import { Strategy } from 'passport-discord-auth';
// CommonJS
const { Strategy } = require('passport-discord-auth');
passport.serializeUser((user, done) => {
  done(null, user);
});

passport.deserializeUser((user, done) => {
  done(null, user);
});

passport.use(
  new Strategy(
    {
      clientID: 'CLIENT_ID',
      clientSecret: 'CLIENT_SECRET',
      callbackURL: 'http://localhost:3000/auth/discord/callback',
      scope: ['identify', 'guilds'],
    },
    (accessToken, refreshToken, profile, done) => {
      // Do something with the profile
      done(null, profile);
    }
  )
);

app.get('/auth/discord', passport.authenticate('discord'));
app.get(
  '/auth/discord/callback',
  passport.authenticate('discord', {
    failureRedirect: '/auth/discord',
  }),
  (req, res) => {
    res.redirect('/');
  }
);

Scope

import { Scope } from 'passport-discord-auth';

// ...

passport.use(
  new Strategy(
    {
      // ...
      scope: [Scope.Identify, Scope.Guilds, Scope.Email],
    }
    // ...
  )
);

Package Sidebar

Install

npm i passport-discord-auth

Weekly Downloads

22

Version

1.1.1

License

CC-BY-NC-SA-4.0

Unpacked Size

145 kB

Total Files

10

Last publish

Collaborators

  • slekup