- Notifications
You must be signed in to change notification settings - Fork1
A Passport strategy for authenticating withhttps://discordapp.com/
License
Opti-domains/passport-discord
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A fully typedPassport strategy for authenticating users withDiscord 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 usingConnect-style middleware, includingExpress.
@oauth-everything/passport-discord
is an authentication Strategy forPassport that allows users to authenticate using theirDiscord account.
$ npm install @oauth-everything/passport-discord
Typescript Example
importexpressfrom'express';importpassportfrom'passport';// Import the strategy and types from@oauth-everything/passport-discordimport{Strategy,Profile,VerifyCallback/*, Scope*/}from'@oauth-everything/passport-discord';// Set up express/connect/etcconstapp=express();app.use(...);......// Set up passportpassport.serializeUser((user:User,done)=>{done(null,/* user.id */);})passport.deserializeUser((id:string,done)=>{done(null,/* database.getUserById(id) */);});......// Set up the Discord Strategypassport.use(newStrategy({// 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 informationscope:[Scope.EMAIL,Scope.GUILDS_JOIN,"webhook.incoming", ...]},(accessToken:string,refreshToken:string,profile:Profile,cb:VerifyCallback<User>)=>{// `profile` will be the user's Discord profileconsole.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/etcapp.get("/auth/discord",passport.authenticate("discord"));app.get("/auth/discord/callback",passport.authenticate("discord",{failureRedirect:"/login",successRedirect:"/"}));// Start the appapp.listen(80);
Javascript Example
constexpress=require('express');constpassport=require('passport');// Import the strategy from@oauth-everything/passport-discordconst{ Strategy/*, Scope*/}=require('@oauth-everything/passport-discord');// Set up express/connect/etcconstapp=express();app.use(...);......// Set up passportpassport.serializeUser((user,done)=>{done(null,/* user.id */);})passport.deserializeUser((id,done)=>{done(null,/* database.getUserById(id) */);});......// Set up the Discord Strategypassport.use(newStrategy({// 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 informationscope:[Scope.EMAIL,Scope.GUILDS_JOIN,"webhook.incoming", ...]},(accessToken,refreshToken,profile,cb)=>{// `profile` will be the user's Discord profileconsole.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/etcapp.get("/auth/discord",passport.authenticate("discord"));app.get("/auth/discord/callback",passport.authenticate("discord",{failureRedirect:"/login",successRedirect:"/"}));// Start the appapp.listen(80);
Click to expand
Go tohttps://discordapp.com/developers/applications and create a New Application
Copy the Client ID and Client Secret and save them somewhere safe
Go to the OAuth tab and add a redirect URL - this will be the URL on your website where Passport is set up
About
A Passport strategy for authenticating withhttps://discordapp.com/
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Languages
- TypeScript100.0%