Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (state === null || state !== storedState) {
res.redirect('/#/error/statemismatch');
} else {
var authOptions = {
url: 'https://accounts.spotify.com/api/token',
form: {
code,
redirect_uri,
grant_type: 'authorization_code'
},
headers: {
'Authorization': 'Basic ' + (new Buffer(client_id + ':' + client_secret).toString('base64'))
},
json: true
};
request.post(authOptions, function (error, response, body) {
if (!error && response.statusCode === 200) {
const access_token = body.access_token,
refresh_token = body.refresh_token;
const options = {
url: 'https://api.spotify.com/v1/me',
headers: { 'Authorization': 'Bearer ' + access_token },
json: true
};
// use the access token to access the Spotify Web API
request.get(options, function (error, response, body) {
const data = {
'accessToken': access_token,
'refreshToken': refresh_token,
'me': body
}
res.cookie('spotify-access', access_token);
function authorize (req, res) {
var token = req.body.payment.token;
var shippingContact = req.body.payment.shippingContact;
var billingContact = req.body.payment.billingContact;
request.post({
url: process.env.PSP_URL,
headers: {
Authorization: 'Basic ' + Buffer.from(process.env.PSP_USERNAME + ':' + process.env.PSP_PASSWORD).toString('base64')
},
json: true,
body: {
merchant_account_id: process.env.PSP_MERCHANT_ACCOUNT_ID,
order_no: '0000001', // test order no
payment: {
payment_id: '089e4cd378bff63d9d7bd63f8f', // test UUID
type: 'ApplePay',
amount: req.body.amount * 100,
currency: 'USD',
token: Buffer.from(JSON.stringify(token.paymentData))
.toString('base64')
},
}
// Build up the request to get the XLS
const options = {
method: 'GET',
url: 'https://vsac.nlm.nih.gov/vsac/pc/vs/report/excel/summaries',
headers: {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Authorization': `Basic ${new Buffer(`${user}:${pass}`).toString('base64')}`
},
// eslint-disable-next-line max-len
body: '{"query":"***ListAll***","cms":null,"category":null,"developers":null,"codeSystems":null,"program":"all","releaseLabel":"Latest"}'
};
// Note: request-promise-native discourages use of pipe, so we must use normal request instead
request.post(options)
.on('error', callback)
.pipe(fs.createWriteStream(file))
.on('finish', callback);
}
function apiAuthenticate (username, password) {
showLoadingBar('Logging in as ' + chalk.bold.underline(username) + '...')
request.post({url: 'https://api.path.com/3/user/authenticate', formData: {post: JSON.stringify({
login: username,
password: password,
client_id: 'MzVhMzQ4MTEtZWU2Ni00MzczLWE5NTItNTBhYjJlMzE0YTgz',
reactivate_user: 1
})}
}, function optionalCallback (err, httpResponse, body) {
clearInterval(loadingInterval)
if (err) {
ui.updateBottomBar(chalk.red('✗') + ' LOGIN FAILURE. ')
return console.error('Error:', err)
}
userJson = JSON.parse(body)
if (userJson.error_code) {
ui.updateBottomBar(chalk.red('✗') + ' LOGIN FAILURE. ')
console.error('Reason:', userJson.error_reason)
return process.exit()
}
}).on('error', exit);
let bz;
if (url && url.slice(-3) === 'bz2') {
bz = spawn('bunzip2');
} else {
const str = new stream.PassThrough();
bz = {
stdin: str,
stdout: str,
};
}
bz.stdin.on('error', exit);
bz.stdout.on('error', exit);
inStream.pipe(bz.stdin);
const parser = request.post(config.PARSER_HOST).on('error', exit);
bz.stdout.pipe(parser);
const parseStream = readline.createInterface({
input: parser,
});
parseStream.on('line', (e) => {
try {
e = JSON.parse(e);
if (e.type === 'epilogue') {
console.log('received epilogue');
incomplete = false;
parseStream.close();
exit();
}
entries.push(e);
} catch (err) {
exit(err);
]).then(function (answers) {
cli_helper_1.Cli.hideBanner = true;
request.post(loginEndPoint, {
body: JSON.stringify({ email: answers.email, password: answers.password }),
headers: {
'Content-Type': 'application/json'
}
}, function (err, response, body) {
cli_helper_1.Cli.log('');
if (err) {
cli_helper_1.Cli.log(err);
cli_helper_1.Cli.log('');
cli_helper_1.Cli.exit(1);
}
if (response.statusCode == 201) {
let json = JSON.parse(body);
if (/[a-z0-9]{16}/.test(json.data.token)) {
service.set('email', answers.email);
service.set('token', json.data.token)
function inviteUser(channelId, userId) {
request.post({
url: 'https://slack.com/api/channels.invite',
auth: {
'bearer': process.env.SLACK_API_TOKEN
},
json: {
'channel': channelId,
'user': userId
}
},
function (error, response, body) {
if (error || !body['ok']) {
console.log('Error inviting user for channel');
console.log(body, error);
}
});
}
function message(userId, message, cb) {
return request.post({
url: auth('user/' + userId + '/message'),
json: {message: message}
}, function (err, res) {
if (err || res.statusCode !== 204) {
err = err || {error: res.body};
return cb(err);
};
return cb();
});
}
fetchCompletionGroups: function(cb){
request.post('http://localhost:9010/repl',
{
auth: {user:this.user, pass:this.password, sendImmediately:false},
json: {cmd:"Object.keys(getObjectProperties(this)).sort();", mldb:this.database}
},
function(err,resp, body){
cb(body);
});
},
updateDb: function(dbname){
function logout (ctx, next) {
request
.post('/logout')
.end(function (err, res) {
if (err || !res.ok) log('Logout error %s', err || res.error);
});
next();
}