Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const BearerAuth = function(config, options) {
if(typeof config === 'object'
&& _.has(config, 'host')
&& _.has(config, 'username')
&& _.has(config, 'token')
) {
return {
wsdlOptions: {},
authProfile: new soap.BearerSecurity(config.token, options),
getUrl: function(url, filePath) {
// request options
let requestOptions = {
auth: {
bearer: config.token
}
};
requestOptions = _.merge(requestOptions, _.clone(options));
requestOptions.url = url;
return when.promise((resolve, reject) => {
request(requestOptions, function(err, res, body) {
if(err) reject(err);
else if(res.statusCode == 401) reject(new Error('Bearer Auth StatusCode 401: Unauthorized.'));
else fs.writeFile(filePath, body, function(err) {
if(err) reject(err);
module.authBearer = function(token) {
auth = new soap.BearerSecurity(token);
};