Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const BasicAuth = function(config, options) {
if(typeof config === 'object'
&& _.has(config, 'host')
&& _.has(config, 'username')
&& _.has(config, 'password')
) {
return {
wsdlOptions: {},
authProfile: new soap.BasicAuthSecurity(config.username, config.password, options),
getUrl: function(url, filePath) {
// request options
let requestOptions = { 'auth': { 'user': config.username, 'pass': config.password, 'sendImmediately': false } };
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('Basic Auth StatusCode 401: Unauthorized.'));
else fs.writeFile(filePath, body, function(err) {
if(err) reject(err);
else resolve(filePath);
});
});
});
module.authBasic = function(user, pass) {
auth = new soap.BasicAuthSecurity(user, pass);
};
export const setSecurity = (client: ISoapClient, credentials: Credentials) => {
const { username, password } = credentials
client.setSecurity(new BasicAuthSecurity(username, password))
}
createClient(url, opts, (err: any, client: Client) => {
if (err) {
reject(err);
} else {
if (!!options.basicAuth) {
client.setSecurity(new BasicAuthSecurity(options.basicAuth.username, options.basicAuth.password));
}
resolve(client);
}
});
} catch (err) {
soap.createClient(url, {}, function(err, client) {
if (err) {
return callback(err);
}
if (!client) {
return callback(new Error('Could not create client'));
}
exports.client = client;
exports.client.setSecurity(new soap.BasicAuthSecurity(settings.username, settings.password));
return callback(null);
}, endpoint);
}