Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use('/login', function(req, res, next) {
var host = req.protocol + '://' + req.get('host')
passport.use(new SteamStrategy({
returnURL: host + '/return',
realm: host,
apiKey: process.env.STEAM_API_KEY
}, function(identifier, profile, done) { // start tracking the player
steam32 = Number(utility.convert64to32(identifier.substr(identifier.lastIndexOf("/") + 1)))
var insert = profile._json
insert.account_id = steam32
insert.track = 1
players.update({
account_id: steam32
}, {
$set: insert
}, {
upsert: true
}, function(err, num) {
if(err) return done(err, null)
};
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.locals.moment = moment;
app.locals.constants = require('./constants.json');
passport.serializeUser(function(user, done) {
done(null, user.account_id);
});
passport.deserializeUser(function(id, done) {
db.players.findOne({
account_id: id
}, function(err, user) {
done(err, user);
});
});
passport.use(new SteamStrategy({
returnURL: host + '/return',
realm: host,
apiKey: api_key
}, utility.initializeUser));
var basic = auth.basic({
realm: "Kue"
}, function(username, password, callback) { // Custom authentication method.
callback(username === (process.env.KUE_USER || "user") && password === (process.env.KUE_PASS || "pass"));
});
app.use(compression());
app.use("/kue", auth.connect(basic));
app.use("/kue", kue.app);
app.use("/public", express.static(path.join(__dirname, '/public')));
app.use(session({
store: new RedisStore({
client: redis
const sessOptions = {
domain: config.COOKIE_DOMAIN,
maxAge: 52 * 7 * 24 * 60 * 60 * 1000,
secret: config.SESSION_SECRET,
};
// PASSPORT config
passport.serializeUser((user, done) => {
done(null, user.account_id);
});
passport.deserializeUser((accountId, done) => {
done(null, {
account_id: accountId,
});
});
passport.use(new SteamStrategy({
returnURL: `${host}/return`,
realm: host,
apiKey,
}, (identifier, profile, cb) => {
const player = profile._json;
player.last_login = new Date();
queries.insertPlayer(db, player, (err) => {
if (err) {
return cb(err);
}
return cb(err, player);
});
}));
// Compression middleware
app.use(compression());
// Dota 2 images middleware (proxy to Dota 2 CDN to serve over https)
const app = express();
const {config} = require('../config');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const NedbStore = require('express-nedb-session')(session);
const passport = require('passport');
const log = require('../logger')('nodecg/lib/login');
const protocol = ((config.ssl && config.ssl.enabled) || config.login.forceHttpsReturn) ? 'https' : 'http';
// 2016-03-26 - Lange: I don't know what these do?
passport.serializeUser((user, done) => done(null, user));
passport.deserializeUser((obj, done) => done(null, obj));
if (config.login.steam && config.login.steam.enabled) {
const SteamStrategy = require('passport-steam').Strategy;
passport.use(new SteamStrategy({
returnURL: `${protocol}://${config.baseURL}/login/auth/steam`,
realm: `${protocol}://${config.baseURL}/login/auth/steam`,
apiKey: config.login.steam.apiKey
}, (identifier, profile, done) => {
profile.allowed = (config.login.steam.allowedIds.indexOf(profile.id) > -1);
if (profile.allowed) {
log.info('Granting %s (%s) access', profile.id, profile.displayName);
} else {
log.info('Denying %s (%s) access', profile.id, profile.displayName);
}
return done(null, profile);
}));
}
Steam.getStrategy = function(strategies, callback) {
if (Steam.hasOwnProperty('apiKey')) {
passport.use(new passportSteam({
returnURL: module.parent.require('nconf').get('url') + '/auth/steam/callback',
realm: module.parent.require('nconf').get('url'),
apiKey: Steam.apiKey
}, function(identifier, profile, done) {
process.nextTick(function () {
// As Steam Passport does't not provide the username, steamid and avatar information, we have to get from Steam API using http get request.
var clientApiKey = Steam.apiKey,
Steam64Id = identifier.replace('http://steamcommunity.com/openid/id/', ''),
apiUrl = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + clientApiKey + '&steamids=' + Steam64Id,
player = {};
http.get(apiUrl, function(res) {
res.on('data', function(chunck){
var responseObj = JSON.parse(chunck.toString());
player.id = responseObj.response.players[0].steamid;
player.username = responseObj.response.players[0].personaname;
player.avatar = responseObj.response.players[0].avatarfull;
const pathCosts = {
'/api/request': 30,
'/api/explorer': 5,
};
// PASSPORT config
passport.serializeUser((user, done) => {
done(null, user.account_id);
});
passport.deserializeUser((accountId, done) => {
done(null, {
account_id: accountId,
});
});
passport.use(new SteamStrategy({
returnURL: `${host}/return`,
realm: host,
apiKey,
}, (identifier, profile, cb) => {
const player = profile._json;
player.last_login = new Date();
queries.insertPlayer(db, player, true, (err) => {
if (err) {
return cb(err);
}
return cb(err, player);
});
}));
// Compression middleware
app.use(compression());
// Dota 2 images middleware (proxy to Dota 2 CDN to serve over https)
})
);
app.use(passport.initialize());
app.use(passport.session());
//Passport serialization for storing user information within sessions.
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
//SteamStrategy as defined under passport-steam, API key is stored in config.js .
passport.use(new SteamStrategy({
returnURL: 'http://localhost:8080/auth/return',
realm:'http://localhost:8080/',
apiKey: config.steamAPIKey
},
function(identifier, profile, done) {
process.nextTick(function () {
profile.identifier = identifier;
return done(null, profile);
});
}
));
app.get('/', function(req, res) {
var currentEnv = ensureEnvironment();
res.render('index', {
displayName : null,
var r = require('./redis');
var redis = r.client;
passport.serializeUser(function(user, done) {
done(null, user.account_id);
});
passport.deserializeUser(function(id, done) {
db.players.findOne({
account_id: id
}, function(err, user) {
//set token for this player's visit, expires in untrack days time
redis.setex("visit:"+id, 60*60*24*config.UNTRACK_DAYS, id);
done(err, user);
});
});
passport.use(new SteamStrategy({
returnURL: host + '/return',
realm: host,
apiKey: api_key
}, function initializeUser(identifier, profile, done) {
var steam32 = Number(convert64to32(identifier.substr(identifier.lastIndexOf("/") + 1)));
var insert = profile._json;
insert.account_id = steam32;
insert.join_date = new Date();
insert.last_summaries_update = new Date();
done(null, insert);
}));
module.exports = passport;