Forked from miki2826/express_passport_link_compatible.js
Created
March 18, 2017 08:27
-
-
Save cAstraea/85f511eb8f09f8af3d1898ad8f385b07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/auth/facebook', (req, res, next) => { | |
passport.authenticate('facebook', { | |
callbackURL: 'http://localhost:3000/auth/facebook/callback?' + | |
(req.query.redirect_uri ? '&redirect_uri=' + req.query.redirect_uri : '') + | |
(req.query.account_linking_token ? '&account_linking_token=' + req.query.account_linking_token : ''), | |
scope: ['public_profile', 'email', 'user_friends', 'user_likes'] | |
})(req, res, next); | |
}); | |
app.get('/auth/callback/facebook', (req, res, next) => { | |
passport.authenticate('facebook', { | |
callbackURL: 'http://localhost:3000/auth/facebook/callback?' + | |
(req.query.redirect_uri ? '&redirect_uri=' + req.query.redirect_uri : '') + | |
(req.query.account_linking_token ? '&account_linking_token=' + req.query.account_linking_token : ''), | |
scope: ['public_profile', 'email', 'user_friends', 'user_likes'] | |
})(req, res, next); | |
}, (req, res) => { | |
// Successful authentication - link the accounts and redirect. | |
botly.getPSID(req.query.account_linking_token, (err, body) => { | |
//You should handle errors | |
var PSID = body.recipient; | |
req.user.update({PSID: req.user}, (err, data) => { | |
//link done, let's redirect | |
res.redirect(req.query.redirect_uri + '&authorization_code=' + req.user.id); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment