Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
io.set('authorization', function (handshakeData, accept) {
// check if there's a cookie header
if (handshakeData.headers.cookie) {
try {
var cookies = cookieParser.signedCookies(cookie.parse(handshakeData.headers.cookie), config.session.secret);
var sid = cookies.GISportal;
var sessionStore = app.get('sessionStore');
sessionStore.load(sid, function(err, session) {
if(err || !session) {
return accept('Error retrieving session!', false);
}
});
} catch(e) {
console.log(e);
}
} else {
// if there isn't, turn down the connection with a message
public create({headers}: APIRequestContextSource) {
if (!headers.cookie) {
return {};
}
const {secrets, ...parseOptions} = this.opts;
const cookies = parseCookieString(headers.cookie, parseOptions);
// parse signed cookies
if (secrets.length !== 0) {
Object.assign(cookies, signedCookies(cookies, secrets));
}
// parse JSON cookies
return JSONCookies(cookies);
}
}
io.on('connection', function(socket){
socket.room = '';
var cookies = cookieParser.signedCookies(cookie.parse(socket.request.headers.cookie), config.session.secret);
var sid = cookies['collaboration'];
var user = {};
var sessionStore = app.get('sessionStore');
sessionStore.load(sid, function(err, session) {
if (err || !session) {
console.log('no passport');
return 'no passport';
}
var emails = session.passport.user.emails;
user.email = emails[0].value;
user.name = session.passport.user.displayName;
user.provider = session.passport.user.provider;
pub.getSessionId = function (cookie) {
if (typeof cookie !== 'string') {
throw new SessionError('Parameter cookie is required and must be a string type!');
}
var signedCookie = cookies.parse(cookie);
return parseSignedCookie(signedCookie, secret)[key];
};
module.exports = async (cookieString, sessionCookieName, cookieSecret, store) => {
if (cookieString == null)
return null;
let cookies = cookieParser.signedCookies(cookie.parse(cookieString), cookieSecret);
const session = await prominence(store).get(cookies[sessionCookieName]);
return session;
};