passport-discord icon indicating copy to clipboard operation
passport-discord copied to clipboard

TokenError

Open ghost opened this issue 5 years ago • 15 comments

Whenever I go to /api/login/discord, it works normally and redirects me to the discord link. Once authorized, I get redirected to /api/discord/callback but with a TokenError.

TokenError at Strategy.OAuth2Strategy.parseErrorResponse ([Working Directory]\node_modules\passport-oauth2\lib\strategy.js:358:12) at Strategy.OAuth2Strategy._createOAuthError ([Working Directory]\node_modules\passport-oauth2\lib\strategy.js:405:16) at [Working Directory]\node_modules\passport-oauth2\lib\strategy.js:175:45 at [Working Directory]\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl ([Working Directory]\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. ([Working Directory]\node_modules\oauth\lib\oauth2.js:157:7) at IncomingMessage.emit (events.js:202:15) at endReadableNT (_stream_readable.js:1129:12) at processTicksAndRejections (internal/process/next_tick.js:76:17)

Code here: https://pastebin.com/ji1fr5EF

ghost avatar Mar 16 '19 22:03 ghost

Same.

reetou avatar Mar 16 '19 22:03 reetou

Last update was a year ago, this probably broke due to updates. I might make a replacement module tbh.

ghost avatar Mar 16 '19 23:03 ghost

This still works fine for me are you sure you set the clientSecret: CLIENT_SECRET,?

PLASMAchicken avatar Apr 18 '19 12:04 PLASMAchicken

After digging the source code I have found out that if you some parameters wrong to the strategy it gives you this error. Also the callback url should be a global url like https://example.com/discord/auth/ not like /discord/auth.

ZE0TRON avatar May 03 '19 09:05 ZE0TRON

After digging the source code I have found out that if you some parameters wrong to the strategy it gives you this error. Also the callback url should be a global url like https://example.com/discord/auth/ not like /discord/auth.

Yeah, I faced the same issue if you enter any wrong parameter to the strategy it will fail.

thrace19 avatar Apr 05 '20 08:04 thrace19

Also the callback url should be a global url like https://example.com/discord/auth/ not like /discord/auth.

Cannot confirm, works fine without a global url. However, can confirm that if you encounter this error, double check your token/secret and that they are properly set.

ljosberinn avatar Jun 07 '20 16:06 ljosberinn

Please make sure to double check your Client ID && Secret, because I didn't pay attention to them and spent an hour trying to debug a problem that was occuring because my secret was missing a hiphon 😐. Pain.

huss-a avatar May 16 '21 09:05 huss-a

Even after checking all of the parameters to the Strategy it still does this for me.

LingleDev avatar Jul 31 '21 16:07 LingleDev

TokenError at Strategy.OAuth2Strategy.parseErrorResponse (/home/runner/botlistw-1/node_modules/passport-discord/node_modules/passport-oauth2/lib/strategy.js:358:12) at Strategy.OAuth2Strategy._createOAuthError (/home/runner/botlistw-1/node_modules/passport-discord/node_modules/passport-oauth2/lib/strategy.js:405:16) at /home/runner/botlistw-1/node_modules/passport-discord/node_modules/passport-oauth2/lib/strategy.js:175:45 at /home/runner/botlistw-1/node_modules/passport-discord/node_modules/oauth/lib/oauth2.js:191:18 at passBackControl (/home/runner/botlistw-1/node_modules/passport-discord/node_modules/oauth/lib/oauth2.js:132:9) at IncomingMessage.<anonymous> (/home/runner/botlistw-1/node_modules/passport-discord/node_modules/oauth/lib/oauth2.js:157:7) at IncomingMessage.emit (events.js:326:22) at endReadableNT (_stream_readable.js:1241:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

Randomx24 avatar Aug 01 '21 16:08 Randomx24

Can you post a short & reproduceable code sample ( like on Stackoverflow )

PLASMAchicken avatar Aug 01 '21 16:08 PLASMAchicken

After digging the source code I have found out that if you some parameters wrong to the strategy it gives you this error. Also the callback url should be a global url like https://example.com/discord/auth/ not like /discord/auth.

When I'm using the callback URL like this:

router.get( "/redirect", passport.authenticate("discord", { failureRedirect: "/" }), function (req, res) { res.redirect("/info"); } // auth success );

only then the error trigger, so is it safe to redirect the user without passport middleware?

i tried to check user login status with this method req.isAuthenticated(), its reponse is false

mrsaifullah52 avatar Feb 22 '22 19:02 mrsaifullah52

After digging the source code I have found out that if you some parameters wrong to the strategy it gives you this error. Also the callback url should be a global url like https://example.com/discord/auth/ not like /discord/auth.

Yeah, I faced the same issue if you enter any wrong parameter to the strategy it will fail. i still get the error

prbhanu avatar Mar 26 '22 12:03 prbhanu

i still get the error

https://stackoverflow.com/help/how-to-ask

You get the error because of user-error, your parameters are wrong can you provoide a minimal repoduceable sample code....?

PLASMAchicken avatar Mar 28 '22 12:03 PLASMAchicken

I got this error, it was because i was using public key instead of client secret. I'm pretty dumb i know, but i'm sharing in case anyone is as dumb as me.

benji4411 avatar Dec 28 '22 19:12 benji4411

I got this error, it was because i was using public key instead of client secret. I'm pretty dumb i know, but i'm sharing in case anyone is as dumb as me.

Thanks benji4411, i also did the same thing 😂, it worked now.

ManrajSaini avatar Sep 18 '23 06:09 ManrajSaini