passport-discord | Passport strategy for authentication with Discord | Authentication library
kandi X-RAY | passport-discord Summary
kandi X-RAY | passport-discord Summary
Passport strategy for authentication with Discord (discordapp.com)
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Strategy constructor .
- Check if the request is logged in
passport-discord Key Features
passport-discord Examples and Code Snippets
Community Discussions
Trending Discussions on passport-discord
QUESTION
I am following a pretty simple tutorial on setting up discord authentication via passport. Earlier this script was working, and now it isn't, I am not sure what I changed.
auth.js
...ANSWER
Answered 2021-Nov-11 at 20:34In my app.js I forgot to include
QUESTION
I am using Nodejs Mongoose here But when i Try to replace Callback to promise It Gives me an error (Failed to serialize user into session) What should I do ?
I'm using passport.serializeUser and passport.deserializeUser but it gives this error
...ANSWER
Answered 2021-Apr-06 at 08:56According to here https://mongoosejs.com/docs/promises.html#built-in-promises
If you are going to use async/await
you need to add .exec()
QUESTION
I think I am doing this wrong.
How can I authorize a user and send the access token to the frontend (Angular) and also make api requests to fetch the user's avatar..etc
In my application, I use discord oauth2 with passport-discord. I call my backend (nodejs) like like this:
...ANSWER
Answered 2021-Apr-02 at 09:44Why are you sending the expiration time of 3600s separately? That information of token expiry that you are declaring 6h is itself in the token.
Instead of sending the token as a plain JSON, try adding it to the header
QUESTION
I have a root @types
and src
folder
ANSWER
Answered 2021-Jan-18 at 10:55How about using ts-node with files
option?
QUESTION
I have been trying to figure this out for 2 days now.
when I go to this route '/profile' deserializeUser works fine
However, when the user authinticate and is redirected back to the callback url, deserialzeUser is not called.
my redirect:
...ANSWER
Answered 2020-Sep-30 at 13:34I found my mistake.
Just remove
sameSite: true,
from the sessionconfig
QUESTION
import passportDiscord from "passport-discord";
passport.serializeUser(function(user, done) { done(null, user); });
passport.deserializeUser(function(user, done) { done(null, user); });
passport.use(new DiscordStrategy({
clientID: OAuth.Discord.Client,
clientSecret: OAuth.Discord.Secret,
callbackURL: OAuth.Discord.Callback,
scope: ['identify', 'email']
},
function(accessToken, refreshToken, profile, cb) {
const avatarUrl = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.png`;
User.findOrCreate({ userAuthName: 'Discord', userAuthId: profile.id, userName: profile.username, userEmail: profile.email, userEnum: '0001', userAvatar: avatarUrl }, function(err, user) {
process.nextTick(function() {
return cb(err, user);
});
});
}));
auth.get('/discord', passport.authenticate('discord'));
auth.get('/discord/callback', passport.authenticate('discord', {
failureRedirect: '/'
}), function (req: any, res: any) {
User.addLog(req.user.userUniqueId, 'logged_in', Host.getAddress(req));
let token = User.createJWT(req.user);
res.cookie('token', token, {maxAge: Core.JWT.expiryMax, domain: Core.cookieUrl})
res.cookie('world', req.user.userWorld, { domain: Core.cookieUrl });
res.end();
return res.redirect(Core.webProtocol + "://" + Core.webUrl)
});
...ANSWER
Answered 2020-Jul-27 at 23:26After 11 days of struggling on this issue, the solution is
Do not use
res.end()
beforereturn res.redirect()
which sounds obvious now but I was too clueless to notice.Instead of using
res.redirect()
we manually wrote headers using301
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install passport-discord
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page