You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.
Hello, I've got an issue that I've been trying trying to fix since few days. So the passport.socketio keeps telling me failed connection to socket.io. No session found There is the code :
var express = require('express');
var session = require('express-session');
var MySQLStore = require('express-mysql-session')(session);
var passportSocketIo = require("passport.socketio");
var session = require('express-session');
var cookieParser = require('cookie-parser');
var sessionStore = new MySQLStore({
checkExpirationInterval: 900000,// How frequently expired sessions will be cleared; milliseconds.
expiration: 86400000,// The maximum age of a valid session; milliseconds.
createDatabaseTable: true,// Whether or not to create the sessions database table, if one does not already exist.
schema: {
tableName: 'sessions',
columnNames: {
session_id: 'session_id',
expires: 'expires',
data: 'data'
}
}
}, mysqlConnection);
var app = express();
app.use(cookieParser());
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use('/public', express.static('public'));
var sessionMiddleware = app.use(session({
secret: 'your secret',
name: 'name of session id',
resave: true,
saveUninitialized: true,
store:sessionStore}));
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
passport.use(new SteamStrategy({
returnURL: domain+'auth/steam/return',
realm: domain,
apiKey: apiKey
},
function(identifier, profile, done) {
process.nextTick(function () {
profile.identifier = identifier;
return done(null, profile);
});
}
));
app.get('/logout', function(req, res){
req.logout();
res.redirect('/');
});
app.get('/auth/steam',
passport.authenticate('steam', { failureRedirect: '/' }),
function(req, res) {
res.redirect('/');
});
var server = app.listen(80);
var io = require('socket.io')(server);
function onAuthorizeSuccess(data, accept){
console.log('successful connection to socket.io');
accept();
}
function onAuthorizeFail(data, message, error, accept){
console.log('failed connection to socket.io:', message);
accept();
}
io.use(passportSocketIo.authorize({
cookieParser: cookieParser, // the same middleware you registrer in express
key: 'express.sid', // the name of the cookie where express/connect stores its session_id
secret: 'session_secret', // the session_secret to parse the cookie
store: sessionStore, // we NEED to use a sessionstore. no memorystore please
success: onAuthorizeSuccess, // *optional* callback on success - read more below
fail: onAuthorizeFail
}));
io.on('connection', function(socket) {
console.log(socket.request.user);
});
The text was updated successfully, but these errors were encountered:
Hello, I've got an issue that I've been trying trying to fix since few days. So the passport.socketio keeps telling me failed connection to socket.io. No session found There is the code :
The text was updated successfully, but these errors were encountered: