jaredhanson / passport-oauth2

OAuth 2.0 authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-oauth2/?utm_source=github&utm_medium=referral&utm_campaign=passport-oauth2&utm_content=about
MIT License
605 stars 343 forks source link

InternalOAuthError: Failed to obtain access token #170

Closed jman13378 closed 1 year ago

jman13378 commented 1 year ago

Hello!

I was trying to use DiscordStrategy but I get the following error

InternalOAuthError: Failed to obtain access token (status: 429 data: error code: 1015)
    at Strategy.OAuth2Strategy._createOAuthError (/home/runner/RecklessProductiveCygwin/node_modules/passport-oauth2/lib/strategy.js:422:17)
    at /home/runner/RecklessProductiveCygwin/node_modules/passport-oauth2/lib/strategy.js:177:45
    at /home/runner/RecklessProductiveCygwin/node_modules/oauth/lib/oauth2.js:191:18
    at passBackControl (/home/runner/RecklessProductiveCygwin/node_modules/oauth/lib/oauth2.js:132:9)
    at IncomingMessage.<anonymous> (/home/runner/RecklessProductiveCygwin/node_modules/oauth/lib/oauth2.js:157:7)
    at IncomingMessage.emit (node:events:539:35)
    at IncomingMessage.emit (node:domain:475:12)
    at endReadableNT (node:internal/streams/readable:1345:12)

here's my strategy

const DiscordStrategy = require('passport-discord').Strategy
const passport = require('passport')
const DiscordUser = require('../models/DiscordUser')

passport.serializeUser((user,done)=>{
    done(null,user.id)
})  

passport.deserializeUser(async (id,done)=>{
    const user = await DiscordUser.findById(id)
    if(user) done(null,user)
})

passport.use(new DiscordStrategy({
    clientID: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    callbackURL: process.env.CLIENT_REDIRECT,
    scope:['identify','guilds']
},async (accessToken,refreshToken,profile,done)=>{
    console.log(profile)
    try{
        const user = await DiscordUser.findOne(profile.id)
        if(user){
            done(null,user) //invokes passport serialization function (attaches user sesssion into request object )
        }
        else{
            const newUser = await DiscordUser.create({
                discordId:profile.id,
                username:profile.username,
                guilds:profile.guilds
            })

            const savedUser = await newUser.save()
            done(null,savedUser)
        }

    }catch(e){
        console.log(e)
        done(e,null)
    }

}))
tommoor commented 1 year ago

All the details are there in the error, this is not a problem with this module.

https://www.google.com/search?q=discord+error+code+1015

jman13378 commented 1 year ago

Yeah its a discord issue