我正在使用Meanjs.org样板和Facebook注册将我返回到注册页面.以下是我到目前为止所采取的步骤.
1)设置Facebook应用程序站点URL
和OAuth的回调URI
2)将APP_ID和APP_Secret放在Client_ID和Client_Secret中
facebook: {
clientID: process.env.FACEBOOK_ID || '*****',
clientSecret: process.env.FACEBOOK_SECRET || '*****',
callbackURL: 'http://localhost:3000/auth/facebook/callback',
profileFields: ['id','emails', 'first_name', 'last_name', 'displayName', 'link', 'about_me', 'photos' ]
},
Run Code Online (Sandbox Code Playgroud)
3)代码如下
--Routes
// Setting the facebook oauth routes
app.route('/auth/facebook').get(passport.authenticate('facebook', {
scope: ['email']
}));
app.route('/auth/facebook/callback').get(users.oauthCallback('facebook'));
Run Code Online (Sandbox Code Playgroud)
- oauthCallback函数,
exports.oauthCallback = function(strategy) {
return function(req, res, next) {
passport.authenticate(strategy, function(err, user, redirectURL) {
if (err || !user) {
console.log('1' + err);
//console.log(user);
return res.redirect('/#!/signin');
}
req.login(user, …Run Code Online (Sandbox Code Playgroud)