0
私は、Express、mongoose、passport/passport-facebookモジュールを使ってFacebookにログインしています。Express with
認証用に作成したコントローラで処理したいと思っています。私は、サーバーをアクティブにすると、端末にそのメッセージをトリガー:
if (!verify) { throw new TypeError('OAuth2Strategy requires a verify callback
^
TypeError: OAuth2Strategy requires a verify callback
は、これは私のコードです:
UserControllerで
var mongoose = require('mongoose');
var passport = require('passport');
var FacebookStrategy = require('passport-facebook').Strategy;
var Account = require('../models/accounts');
var Project = require('../models/projects');
var Message = require('../models/messages');
var Follow = require('../models/follows');
var apiKeys = require('../apiKeys');
{more code}
fbAuth : function(access_token, refresh_token, profile, done){
console.log("*************");
console.log("entra en fbAuth");
console.log("*************");
Account.findOne({'providerId' : profile.id}, function(err, user){
if(err){
return done(err);
}
if(user){
return done(null, user);
}
else{
var newUser = new Account({
emailAccount : profile.emails[0].value,
provider : profile.provider,
providerId : profile.id,
username : profile.name.givenName,
});
newUser.save();
}
});
passport.authenticate('facebook',{
successRedirect : '/user',
failureRedirect : '/'
});
},
fbAuthSuccess : function (req, res){
passport.authenticate('facebook', {
successRedirect : '/user',
failureRedirect : '/'
});
},
ルート
router.get('/facebook', controller.fbAuth);//passport.authenticate('facebook', { scope : 'email' }));
router.get('/facebook/callback', passport.authenticate('facebook', {
successRedirect : '/user',
failureRedirect : '/'
});
app.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var mongoose = require('mongoose');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var FacebookStrategy = require('passport-facebook').Strategy;
var session = require('express-session');
var socket = require('socket.io');
var apiKeys = require('./apiKeys');
var app = express();
{more code}
passport.use(new LocalStrategy(Account.authenticate()));
passport.serializeUser(Account.serializeUser());
passport.deserializeUser(Account.deserializeUser());
//social facebook
passport.use(new FacebookStrategy({
clientID: apiKeys.facebook.appID,
clientSecret: apiKeys.facebook.appSecret,
callbackURL: apiKeys.facebook.callbackUrl,
'profileFields': ['id', 'displayName', 'email', 'name'],
}));
もっと良く説明してください。 –