nicholastay / passport-discord

Passport strategy for authentication with Discord (discordapp.com)
ISC License
172 stars 55 forks source link

Callback Never Runs #30

Open Altanis opened 3 years ago

Altanis commented 3 years ago
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?

KingCh1ll commented 3 years ago

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