简体   繁体   English

护照会议明确要求

[英]Passport session clear req.session

I'm coding a session with NodeJS, when I get the user connection first create a session.client with the MAC ADDRESS, so far so good, but then I ask to the client if he want to continue and login on the app with social -network like Facebook, Instagram, Tweeter or Google+, and then when the user is redirected to the social login it back with other session from passportjs and clear al my init data of session and I lost the client information. 我正在使用NodeJS编写会话,当我获得用户连接时,首先使用MAC ADDRESS创建一个session.client,到目前为止一切顺利,但随后我问客户端是否要继续并使用社交网络登录应用程序-Facebook,Instagram,Tweeter或Google+等网络,然后当用户重定向到社交登录时,它将与其他会话从passwordjs返回,并清除会话的初始数据,而我丢失了客户信息。 So, I tried to change the name of the data in session, session.data, session.test, session.whatever but always happen the same, when I test and the passport redirect me and back to my domain, the session is clean and it change with new data from passportjs, any one know what's happen here? 因此,我尝试更改会话,session.data,session.test,session。中的数据名称,但是总是发生相同的情况,当我进行测试并且护照将我重定向并返回我的域时,该会话是干净的,它随着来自passwordsjs的新数据而变化,有人知道这里发生了什么吗? any idea how to solve this? 任何想法如何解决这个问题?

the code run perfectly, the problem is the session when go and back to // the social login, it clear my init data and back with the passport data. 代码运行得很好,问题在于返回社交登录时的会话,//清除了我的初始化数据并返回了护照数据。 // I need my init data to continue working! //我需要初始化数据才能继续工作!

this is just an extract of code. 这只是代码的一部分。 It works 有用

 'use sctrict' const https = require('https'), fs = require('fs'), path = require('path'), morgan = require('morgan'), logger = require('express-logger'), express = require('express'), favicon = require('serve-favicon'), bodyParser = require('body-parser'), methodOverride = require('method-override'), passport = require('passport'), // config files port = 443, mongodbConfig = require('./config/mongodb-config'), session = require('express-session'), keys = require('./config/keys'), options = { key: fs.readFileSync('./config/ssl/server.key'), cert: fs.readFileSync('./config/ssl/server.crt') }, cookieParser = require('cookie-parser'), loginAPRoutes = require('./routes/loginAPRoutes'), passportSetup = require('./config/passport-setup'), app = express() // MongoDB - Mongoose connection const mongoose = require('mongoose') mongoose.Promise - global.Promise mongoose.connect('mongodb://' + mongodbConfig.mongodb.route + '/' + mongodbConfig.mongodb.db, {}) .then(() => console.log('db connected')) .catch(err => console.log(err)) // config app.set('view engine', 'ejs') // middlewares app.use(morgan('dev')) app.use(favicon(path.join(__dirname, 'public/img/', 'favicon.ico'))) app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.json()) app.use(methodOverride('X-HTTP-Method-Override')) app.use(express.static(path.join(__dirname, 'public'))) app.use(session({ secret: 'cybor-cat', resave: false, saveUninitialized: true })) // initilize passport app.use(passport.initialize()) app.use(passport.session()) // Main routes app.use('/guest', loginAPRoutes) app.use('/auth', loginAPRoutes) // Run the server https https.createServer(options, app).listen(port, () => { console.log('NodeJS Server Started... splice.pro is running!') }) router.get('/s/:site', (req, res) => { data = req.query data.site = req.params.site req.session.data = data console.log('===== session ========') console.log(req.session) console.log('====== session END =======') res.render('login') }) /////////////// GOOGLE AUTH //////////////// // route for google login router.get('/google', passport.authenticate('google', { scope: ['profile', 'email'] })) // route for google and redirect router.get('/google/callback', passport.authenticate('google'), (req, res) => { if (!req.user) { res.redirect('/guest/s/site') } else { /////////// here comes the new session from passport :( ////// ////////// and lost the first data of my session ///// console.log(req.session.data) //////////////// this show the session with info of user /////// /////////////// but req.session.data is lost /////////// res.redirect('/guest/startconnection') } } ) /////////////// GOOGLE AUTH END //////////////// 

好吧,好吧....我发现了我的问题,我的外部站点使用ip将我重定向到了我的服务器,当护照登录请求重定向时,它又回到了域名,这就是为什么它会生成一个新的会话ID的原因。 ..漫长的一天但是最后我找到了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM