Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const refreshToken = (curUser, req, res, origin) => {
refresh.requestNewAccessToken('google', curUser.refreshToken,
(err, newAccessToken) => {
if (err) {
console.error('ERROR at refreshToken requestNewAccessToken', err);
return res.status(500).send('ERROR at refreshToken requestNewAccessToken');
}
curUser.accessToken = newAccessToken;
curUser.save((err) => {
if (err) {
console.error('ERROR at save curUserrequestNewAccessToken', err);
return res.status(500).send('ERROR at save curUserrequestNewAccessToken');
}
/* eslint-disable */
switch (origin) {
case 'getCalList':
return getCalList(req, res, curUser, true);
case 'getCalEventsList':
/**
* Setup mercadolibre passport Strategy.
*
* @type {Strategy}
*/
const mercadoLibreStrategy = new MercadoLibreStrategy({
clientID: clientId,
clientSecret,
callbackURL: '/auth/mercadolibre/callback'
},
authorizedCb
)
passport.use(mercadoLibreStrategy)
refresh.use(mercadoLibreStrategy)
// Add promise support to refresh
refresh.requestNewAccessToken = Promise.promisify(refresh.requestNewAccessToken)
module.exports = meliAuth
return new Promise((resolve, reject) => {
oauthrefresh.use(getStrategy(params.app.config));
oauthrefresh.requestNewAccessToken('google', user.google.refreshToken, function(err, accessToken, refreshToken) {
if (err) {
return reject(err);
}
if (!accessToken) {
return reject(new Error('refresh google access token give no result'));
}
user.google.accessToken = accessToken;
if (refreshToken) {
// should be the same of the initial refresh token
user.google.refreshToken = refreshToken;
}
return new Promise((resolve, reject) => {
oauthrefresh.use(getStrategy(params.app.config));
oauthrefresh.requestNewAccessToken('google', user.google.refreshToken, function(err, accessToken, refreshToken) {
if (err) {
return reject(err);
}
if (!accessToken) {
return reject(new Error('refresh google access token give no result'));
}
user.google.accessToken = accessToken;
if (refreshToken) {
// should be the same of the initial refresh token
user.google.refreshToken = refreshToken;
}
resolve(user.save());
});
const strategyOptions1: StrategyOptions = {
authorizationURL: 'http://www.example.com/auth',
callbackURL: 'http://www.example.com/callback',
clientID: 'dummy',
clientSecret: 'secret',
tokenURL: 'http://www.example.com/token'
};
function verifyFunction1(_accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) {
verifyCallback(new Error('unimplemented'));
}
const strategy1: OAuth2Strategy = new OAuth2Strategy(strategyOptions1, verifyFunction1);
use('strategy1', strategy1);
requestNewAccessToken('strategy1', 'exampleRefreshToken', (err, accessToken, refreshToken, results) => {});
requestNewAccessToken('strategy1', 'exampleRefreshToken', {}, (err, accessToken, refreshToken, results) => {});
authorizationURL: 'http://www.example.com/auth',
callbackURL: 'http://www.example.com/callback',
clientID: 'dummy',
clientSecret: 'secret',
tokenURL: 'http://www.example.com/token'
};
function verifyFunction1(_accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) {
verifyCallback(new Error('unimplemented'));
}
const strategy1: OAuth2Strategy = new OAuth2Strategy(strategyOptions1, verifyFunction1);
use('strategy1', strategy1);
requestNewAccessToken('strategy1', 'exampleRefreshToken', (err, accessToken, refreshToken, results) => {});
requestNewAccessToken('strategy1', 'exampleRefreshToken', {}, (err, accessToken, refreshToken, results) => {});
async (user, next) => {
try {
const userLookup = new User(user);
const savedUser = await userLookup.getUser();
const minutesUntilExpiration = getMinutesUntilExpiration(savedUser.timeExpires);
if (minutesUntilExpiration < 0) {
refresh.requestNewAccessToken('spotify', savedUser.refreshToken, async (err, accessToken, refreshToken) => {
if (err) {
console.error(err);
}
try {
const timeExpires = getTimeExpires();
const { id } = savedUser;
const userForSave = new User({ id, accessToken, timeExpires });
const updatedUser = await userForSave.updateAccessToken();
next(null, updatedUser);
} catch (e) {
console.error(e);
}
});
} else {
export const setup = (User, config) => {
passport.use(strategy(User, config));
refresh.use(strategy(User, config));
};
done(success);
}
});
});
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (user, done) {
done(null, user);
});
//Extend some stuff
passport.use('provider', oauthStrategy);
refresh.use('provider', oauthStrategy);
app.use(session({
store: new mongoStore({ db: database.db }),
secret: setup.data.sessionSecret,
cookie: { maxAge: 604800 * 1000 }, //Week long cookies for week long incursions!
resave: true,
saveUninitialized: true
}))
app.use(cookieParser());
app.use(session({ secret: setup.data.sessionSecret }));
app.use(flash({ locals: 'flash' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/includes', express.static('public/includes'));
app.use(users.updateUserSession); //Force the session to update from DB on every page load because sessions are not the source of truth here!
e => cb(e)
)
}
});
}
var spotify = new SpotifyStrategy({
clientID: config.get('auth.spotify.clientId'),
clientSecret: config.get('auth.spotify.clientSecret'),
callbackURL: callbackUrl('spotify')
}, _callback
);
passport.use(spotify);
refresh.use(spotify);
passport.serializeUser(function(user, cb) {
cb(null, user._id);
});
passport.deserializeUser(function(id, cb) {
var User = deps.models.User;
User.findById(id).select('+access_token').lean().exec(cb);
});
return passport;
};