Sunday, 30 April 2017

Passport.js Github Strategy on Node.js: Github redirect_uri mismatch

I want to implement a login with Passport.js and Github Strategy. The code works fine on localhost, but when I host it on Digital Ocean, I get this:

AuthorizationError: The redirect_uri MUST match the registered callback URL for this application.

I would like to invite tou to take a look over the code and to help me to fink out what is the problem. I mention that I tested a lot of combination for Github Homepage/Github Callback/Local Callback, but it doesn't work. My setup look like this:

// Github OAuth app
Homepage URL: http://example.com:3000
Callback URL: http://example.com:3000/auth/github/callback

// part of config.js
var config = {
        githubID: '',
        githubSecret: '',
        githubURL: 'http://example.com:3000/auth/github/callback',
    }

// part of app.js
passport.use(new GithubStrategy({
        clientID: config.githubID,
        clientSecret: config.githubSecret,
        callbackURL: config.githubURL
    },
    function(accessToken, refreshToken, profile, done){
        process.nextTick(function(){
            return done(null, profile);
        });
    }
));

app.get('/auth/github', passport.authenticate('github', {scope: ['user:email']}), function(req, res){});
app.get('/auth/github/callback', passport.authenticate('github', {failureRedirect: '/'}), function(req, res){
    res.redirect('/dashboard');
});
app.get('/logout', function(req, res){
    req.logout();
    res.redirect('/');
});



via George Andrei Iosif

No comments:

Post a Comment