passport-discord-auth
v1.1.1
Published
An updated passport authentication strategy for Discord.
Downloads
896
Maintainers
Readme
Discord • GitHub
An updated passport authentication strategy for Discord.
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],
}
// ...
)
);