Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.facebooktoken = function (req, res) {
// NOTE: this (ab)uses the passport strategy-specific userProfile method to check if a token is valid.
var fbStrategy = passport._strategies.facebook;
fbStrategy.userProfile(req.body.token, function (err, profile) {
if (err) {
return sendTokenValidationError(res, err);
}
var user = createUserFromProfile(profile);
sendLoggedInResponseForUser(user, res);
});
}
exports.googletoken = function (req, res) {
// NOTE: this (ab)uses the passport strategy-specific userProfile method to check if a token is valid.
var googleStrategy = passport._strategies.google;
googleStrategy.userProfile(req.body.token, function (err, profile) {
if (err) {
return sendTokenValidationError(res, err);
}
var user = createUserFromProfile(profile);
sendLoggedInResponseForUser(user, res);
});
}
function fakeNextPassportLogin(userString) {
passport._strategies.openstreetmap._token_response = {
access_token: "at-1234",
expires_in: 3600
};
passport._strategies.openstreetmap._profile = {
displayName: userString
};
}
}));
System.set('chalk', System.newModule({
bold: require('chalk').bold
}));
System.set('path', System.newModule({
resolve: require('path').resolve
}));
System.set('passport', System.newModule({
use: passport.use,
authenticate: passport.authenticate,
initialize: passport.initialize,
_strategies: passport._strategies,
_strategy: passport._strategy,
_framework: passport._framework
}));
System.set('passport-local', System.newModule({
Strategy: require('passport-local').Strategy
}));
module.exports.getUser = function getUser(options) {
options = options || {};
var id = options.id,
ghostOAuth2Strategy = passport._strategies.ghost;
return new Promise(function (resolve, reject) {
ghostOAuth2Strategy.userProfileByIdentityId(id, function (err, profile) {
if (err) {
return reject(err);
}
resolve(profile);
});
});
};
social(req, res) {
const type = req.param('type') ? req.param('type').toLowerCase() : '-';
const strategyName = [type, 'token'].join('-');
if (Object.keys(passport._strategies).indexOf(strategyName) === -1) {
return res.badRequest(null, {message: [type, ' is not supported'].join('')});
}
passport.authenticate('jwt', (error, user, info) => {
req.user = user;
passport.authenticate(strategyName, _.partial(sails.config.passport.onPassportAuth, req, res))(req, res);
})(req, res);
},
return function jwtAssertionPassportAuthenticateCb(req, res, next) {
var proxyKey = app.get('evproxyInternalKey') || '97b62fa8-2a77-458b-87dd-ef64ff67f847';
if (req.headers && proxyKey) {
if (req.headers['x-evproxy-internal-key'] === proxyKey) {
return next();
}
}
if (process.env.SECRET_OR_KEY && process.env.SECRET_OR_KEY.length > 0) {
Passport._strategies.jwt._secretOrKey = jwtUtil.sanitizePublicKey(process.env.SECRET_OR_KEY);
}
Passport.authenticate('jwt', (err, user, info) => {
if (err) {
return next(err);
}
if (!user) {
return next();
}
if (user) {
var trustedApp = user[jwtConfig.keyToVerify];
var userObj = loopback.getModelByType('BaseUser');
var username = '';
if (trustedApp) {
var rolesToAdd = [];
var appObj = loopback.getModelByType('TrustedApp');