Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function authenticateYoutube(credentials, tokenPath, callback) {
const {client_id, client_secret, redirect_uris} = credentials.web;
const oauth2Client = new OAuth2(client_id, client_secret, redirect_uris[0]);
Google.options({auth: oauth2Client});
if(fileExists(tokenPath)) {
console.log('youtube token already exists');
const tokens = JSON.parse(sh.cat(tokenPath));
oauth2Client.setCredentials(tokens);
// get playlists to check if token is really valid or not
listPlaylists((err, data) => {
if(err) {
console.log('youtube token invalid, getting a new one');
getYoutubeTokens(oauth2Client, tokenPath, callback);
} else {
console.log('youtube token is still valid');
callback(oauth2Client);
}
}, {part: 'id'});
} else {
jwtClient.authorize(function(err, tokens) {
if (err) {
console.info('Ganalytics JWT error ', err);
return err;
}
oauth2Client.setCredentials({access_token: tokens.access_token});
google.options({ auth: oauth2Client });
ganalytics = google.analyticsreporting('v4');
// return ganalytics;
});
jwtClient.authorize(err => {
if (!err) {
google.options({ auth: jwtClient })
resolve(jwtClient)
} else {
console.error(
'Error authorizing with Service Account',
err.message || err
)
reject(err)
}
})
})
},
file
} = req
const {identities} = await getUser(userId)
const {access_token} = identities.find(
identity => identity.provider === 'google-oauth2'
)
auth.setCredentials({
access_token,
})
google.options({auth})
console.log("looking for directory")
let {files} = await driveSearch({
q: `mimeType='${gDirectory}' and name='Knight Images' and appProperties has {key='knight' and value='true'}`,
fields: 'files(id, name, appProperties, permissions)'
})
let knightDirectoryId
if (files.length < 1) {
let {id} = await driveCreate({
resource: {
name: 'Knight Images',
function updateGlobalParams(paramName, value) {
tl.debug("Updating Global Parameters");
tl.debug("SETTING " + paramName + " TO " + JSON.stringify(value));
globalParams.params[paramName] = value;
google.options(globalParams);
tl.debug("Global Params set to " + JSON.stringify(globalParams));
}
function updateGlobalParams(paramName, value) {
tl.debug("Updating Global Parameters");
tl.debug("SETTING " + paramName + " TO " + JSON.stringify(value));
globalParams.params[paramName] = value;
google.options(globalParams);
tl.debug("Global Params set to " + JSON.stringify(globalParams));
}
function discoverGAPI(callback){
auth = new googleapis.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
auth.credentials=tokens;
googleapis.options({auth: auth});
drive = googleapis.drive('v2')
callback();
}
function updateGlobalParams(paramName, value) {
tl.debug("Updating Global Parameters");
tl.debug("SETTING " + paramName + " TO " + JSON.stringify(value));
globalParams.params[paramName] = value;
google.options(globalParams);
tl.debug("Global Params set to " + JSON.stringify(globalParams));
}