Javascript 使用passport.js重定向
我正在使用passport.js、passport google oauth和nodjes加载用户配置文件(本地)。但是登录后的重定向不起作用。信息已加载(登录后我可以转到/google profile)。 这是我的密码Javascript 使用passport.js重定向,javascript,node.js,passport.js,Javascript,Node.js,Passport.js,我正在使用passport.js、passport google oauth和nodjes加载用户配置文件(本地)。但是登录后的重定向不起作用。信息已加载(登录后我可以转到/google profile)。 这是我的密码 var express = require('express'); var passport = require('passport'); var util = require('util'); var GoogleStrategy = require('passport-go
var express = require('express');
var passport = require('passport');
var util = require('util');
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var GOOGLE_CLIENT_ID = "bla";
var GOOGLE_CLIENT_SECRET = "bla";
var userPorifile = {};
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://localhost:8000/auth/google/callback"
},
function(accessToken, refreshToken, profile, done) {
userPorifile = profile;
}
));
var app = express();
app.get('/google-profile', function (req, res) {
res.json(userPorifile);
});
app.get('/login',
passport.authenticate('google', { scope: 'https://www.googleapis.com/auth/plus.login' }));
app.get('/auth/google/callback?*', passport.authenticate('google', { successRedirect : '/google-profile', failureRedirect: '/login' }), function(req, res) {
console.log("done");
res.redirect('/google-profile');
});
app.use(function (req, res, next) {
if (req.query.something) {
next();
} else {
next();
}
});
app.listen(8000);
有人能帮我做这个吗?你应该有这样的东西:
'googleAuth' : {
'clientID' : 'your-secret-clientID-here',
'clientSecret' : 'your-client-secret-here',
'callbackURL' : 'http://localhost:8080/auth/google/callback'
}
在配置文件中,在passport文件中:
passport.use(new GoogleStrategy({
clientID : configAuth.googleAuth.clientID,
clientSecret : configAuth.googleAuth.clientSecret,
callbackURL : configAuth.googleAuth.callbackURL,
},
然后在路线上:
app.get('/auth/google', passport.authenticate('google', { scope : ['profile', 'email'] }));
// the callback after google has authenticated the user
app.get('/auth/google/callback',
passport.authenticate('google', {
successRedirect : '/profile',
failureRedirect : '/'
}));
请注意,我不理解您对“*”的回调,您没有使用express?在使用google进行passport身份验证后,您是否有回调?是的,我设置userPorifile的函数被调用,但我在控制台中没有看到“完成”。所以这个函数不被调用,非常感谢!