我正在尝试使用google身份验证护照-ogle对用户进行身份验证,但它一直在发送 InternalOAuthError:无法获取请求令牌。
错误视图
InternalOAuthError:无法获取请求令牌 Strategy.OAuthStrategy._createOAuthError (/Users/menaka/WebstormProjects/cardCreaterServer/node_modules/passport-oauth1/lib/strategy.js:396:17) 在 /Users/menaka/WebstormProjects/cardCreaterServer/node_modules/passport-oauth1/lib/strategy.js:244:41 在 /Users/menaka/WebstormProjects/cardCreaterServer/node_modules/oauth/lib/oauth.js:543:17 在passBackControl (/Users/menaka/WebstormProjects/cardCreaterServer/node_modules/oauth/lib/oauth.js:397:13) 在IncomingMessage。 (/Users/menaka/WebstormProjects/cardCreaterServer/node_modules/oauth/lib/oauth.js:409:9) 在IncomingMessage.emit的emitNone(events.js:72:20) (events.js:166:7)endReadableNT(_stream_readable.js:921:12)
在nextTickCallbackWith2Args(node.js:442:9)at process._tickCallback(node.js:356:17)
我已经在google API Manager平台内启用了 Google + api 。这是我的 授权的JavaScript来源
和 授权重定向URI
在我的routes.js文件旁边
var User = require('./models/user');
module.exports = function(app, passport){
app.get('/', function(req, res){
res.render('index.ejs');
});
app.get('/login', function(req, res){
res.render('login.ejs', { message: req.flash('loginMessage') });
});
app.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile',
failureRedirect: '/login',
failureFlash: true
}));
app.get('/signup', function(req, res){
res.render('signup.ejs', { message: req.flash('signupMessage') });
});
app.post('/signup', passport.authenticate('local-signup', {
successRedirect: '/',
failureRedirect: '/signup',
failureFlash: true
}));
app.get('/profile', isLoggedIn, function(req, res){
res.render('profile.ejs', { user: req.user });
});
app.get('/auth/google', passport.authenticate('google', {scope: ['profile','email']}));
app.get('/auth/google/callback',
passport.authenticate('google', { successRedirect: '/profile',
failureRedirect: '/' }));
app.get('/logout', function(req, res){
req.logout();
res.redirect('/');
})
};
function isLoggedIn(req, res, next) {
if(req.isAuthenticated()){
return next();
}
res.redirect('/login');
}
在我的passport.js里面
var LocalStrategy = require('passport-local').Strategy;
var GoogleStrategy = require('passport-google-oauth').OAuthStrategy;
var User = require('../app/models/user');
var configAuth=require('./auth');
module.exports = function(passport) {
passport.serializeUser(function(user, done){
done(null, user.id);
});
passport.deserializeUser(function(id, done){
User.findById(id, function(err, user){
done(err, user);
});
});
passport.use('local-signup', new LocalStrategy({
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
},
function(req, email, password, done){
process.nextTick(function(){
User.findOne({'local.username': email}, function(err, user){
if(err)
return done(err);
if(user){
return done(null, false, req.flash('signupMessage', 'That email already taken'));
} else {
var newUser = new User();
newUser.local.username = email;
newUser.local.password = newUser.generateHash(password);
newUser.save(function(err){
if(err)
throw err;
return done(null, newUser);
})
}
})
});
}));
passport.use('local-login', new LocalStrategy({
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
},
function(req, email, password, done){
process.nextTick(function(){
User.findOne({ 'local.username': email}, function(err, user){
if(err)
return done(err);
if(!user)
return done(null, false, req.flash('loginMessage', 'No User found'));
if(!user.validPassword(password)){
return done(null, false, req.flash('loginMessage', 'invalid password'));
}
return done(null, user);
});
});
}
));
passport.use(new GoogleStrategy({
consumerKey: configAuth.GoogleAuth.clientID,
consumerSecret: configAuth.GoogleAuth.clientSecret,
callbackURL: configAuth.GoogleAuth.callbackURL
},
function(accessToken, refreshToken, profile, done) {
process.nextTick(function(){
User.findOne({'google.id':profile.id},function(err,user){
if(err){
return done(err);
}
if(user){
return done(null,user);
}else{
var newUser=new User();
newUser.google.id=profile.id;
newUser.google.token=accessToken;
newUser.google.name=profile.displayName;
newUser.google.email=profile.emails[0].value;
newUser.save(function(err){
if(err){
throw err;
}
return done(null,newUser);
})
}
});
});
}
));
};
callbackURL是
为了解决这个问题,我该怎么做?
答案 0 :(得分:2)
尝试转到mv -f Makefile Makefile.bak
imake -DUseInstalled -I/usr/share/X11/config
make Makefiles
Makefile:1056: *** missing separator. Stop.
和LocalCompileDefault
错误消息,然后查看输出。
答案 1 :(得分:2)
暂时搁置了这一点 - 似乎在基本策略中有一个旧的链接参考。建议你试试
https://github.com/jaredhanson/passport-google-oauth2
代替。它是最新的,并立即为我工作!
*调试解决方案让我解决了这个问题,顺便说一句。