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

Callback Never Runs

Open Altanis opened this issue 4 years ago • 1 comments

const Express = require('express');
const app = Express();

let { Strategy } = require('passport-discord');
let Passport = require('passport');

app.use(Passport.initialize());
app.use(Passport.session());

let tag;

Passport.use(new Strategy({
    clientID: '755551678337515591',
    clientSecret: 'clientsecret',
    callbackURL: '/success',
    scope: ['identify'],
}, (_accessToken, _refreshToken, profile, _callback) => {
  tag = `${profile.username}#${profile.discriminator}`;
}));

app.get('/', async (request, response) => {
    response.redirect('/redirect');
});

app.get('/redirect', Passport.authenticate('discord', {
    failureRedirect: '/fail',
}, async (request, response) => {
    response.redirect('/success');
}));

app.get('/fail', async (request, response) => {
    response.json({
        status: 'error',
        message: 'Failure to fetch OAuth2. Please contact Altanis#6362',
    });
});

app.get('/success', async (request, response) => {
    response.json({
        status: 'success',
        message: `Successfully authorized ${tag} using OAuth2.`,
    });
});

app.listen(3000, () => console.log(`I am requesting and responding from and to port 3000.`));

I tried logging "hello" inside the callback for passport.use, but never runs. I don't see any problems in my code, can someone help me please?

Altanis avatar Oct 12 '20 16:10 Altanis

Are you sure your application is redirecting you to /callback?

KingCh1ll avatar Jun 03 '21 21:06 KingCh1ll