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':
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());
});
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 {
db.findOne({characterID: characterID}, function(err, doc){
refresh.requestNewAccessToken('provider', doc.refreshToken, function(error, accessToken, newRefreshToken){
if(error){
log.error("user.getRefreshToken - requestNewAccessToken: ", {pilot: characterID, error});
tokenCallback(null);
return;
}
db.updateOne({ 'characterID': characterID }, { $set: { refreshToken: newRefreshToken } }, function (err, result) {
if (err) log.error("user.getRefreshToken: Error for updateOne", { err, 'characterID': characterID });
tokenCallback(accessToken);
return;
})
});
})
}