javascriptnode.jspassport.jspassport-local

Can't Authorize using DIscord Passport.js


Each time I get one of these errors when trying to log in to my webapp using discord,

InternalOAuthError: Failed to obtain access token
    at Strategy.OAuth2Strategy._createOAuthError (/home/ec2-user/website/node_modules/passport-oauth2/lib/strategy.js:423:17)
    at /home/ec2-user/website/node_modules/passport-oauth2/lib/strategy.js:177:45
    at /home/ec2-user/website/node_modules/oauth/lib/oauth2.js:191:18
    at passBackControl (/home/ec2-user/website/node_modules/oauth/lib/oauth2.js:132:9)
    at IncomingMessage.<anonymous> (/home/ec2-user/website/node_modules/oauth/lib/oauth2.js:157:7)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

InternalOAuthError: Failed to fetch the user profile.
    at /home/ec2-user/website/node_modules/passport-discord/lib/strategy.js:77:25
    at passBackControl (/home/ec2-user/website/node_modules/oauth/lib/oauth2.js:132:9)
    at IncomingMessage.<anonymous> (/home/ec2-user/website/node_modules/oauth/lib/oauth2.js:157:7)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

InternalOAuthError: Failed to fetch user's guilds
    at /home/ec2-user/website/node_modules/passport-discord/lib/strategy.js:108:32
    at passBackControl (/home/ec2-user/website/node_modules/oauth/lib/oauth2.js:132:9)
    at IncomingMessage.<anonymous> (/home/ec2-user/website/node_modules/oauth/lib/oauth2.js:157:7)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

This is the simple code to the redirection:

router.get('/redirect', checkNotAuth, passport.authenticate('discord', {
  failureRedirect: '/forbidden',
  successRedirect: '/'
}));

This is the link format I am trying to access:

https://dashboard.website.com/auth/discord/redirect?code=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The big issue is that this happens only when deploying to my server, but when I am in the localhost, it works completely fine


Solution

  • I wasn't lying, but really now, it just worked... probably an issue in passport?