Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function(fulfill, reject) {
this.send('request', 'post', kwargs, cb);
kwargs.url = this.enrichUrl(kwargs.url);
kwargs.json = true;
kwargs.method = 'POST';
kwargs.headers = { 'X-Api-Key': this.apiKey };
// Make sure withCredentials is not enabled, different browser
// fallbacks handle it differently by default (meteor)
kwargs.withCredentials = false;
var callback = this.wrapPromiseTask(cb, fulfill, reject);
var req = request(kwargs, callback);
httpSignature.sign(req, {
algorithm: 'hmac-sha256',
key: this.apiSecret,
keyId: this.apiKey,
});
}.bind(this)
);
// methodsThatRequireExtraHeaders ["POST", "PUT"];
if(["POST","PUT"].indexOf(request.method.toUpperCase()) !== -1 )
{
body = body || "";
request.setHeader("content-length", body.length);
headersToSign = headersToSign.concat([ "content-type", "content-length" ]);
if ( request.getHeader('content-type') != 'application/x-www-form-urlencoded' ){
var shaObj = new jsSHA("SHA-256", "TEXT");
shaObj.update(body);
request.setHeader("x-content-sha256", shaObj.getHash('B64'));
headersToSign = headersToSign.concat([ "x-content-sha256" ]);
}
}
httpSignature.sign( request, { key: auth.privateKey,
keyId: auth.tenancyId + "/" +
auth.userId + "/" +
auth.keyFingerprint,
headers: headersToSign } );
var newAuthHeaderValue = request.getHeader("Authorization").replace("Signature ", "Signature version=\"1\",");
request.setHeader("Authorization", newAuthHeaderValue);
};
// methodsThatRequireExtraHeaders ["POST", "PUT"];
if(["POST","PUT"].indexOf(request.method.toUpperCase()) !== -1 )
{
body = body || "";
request.setHeader("content-length", body.length);
headersToSign = headersToSign.concat([ "content-type", "content-length" ]);
if ( request.headers['content-type'] == 'x-www-form-urlencoded' ){
var shaObj = new jsSHA("SHA-256", "TEXT");
shaObj.update(body);
request.setHeader("x-content-sha256", shaObj.getHash('B64'));
headersToSign = headersToSign.concat([ "x-content-sha256" ]);
}
}
httpSignature.sign( request, { key: auth.privateKey,
keyId: auth.tenancyId + "/" +
auth.userId + "/" +
auth.keyFingerprint,
headers: headersToSign } );
var newAuthHeaderValue = request.getHeader("Authorization").replace("Signature ", "Signature version=\"1\",");
request.setHeader("Authorization", newAuthHeaderValue);
};
var parentOcidVal = parentOcidArr[parentOcidArr.length-1];
if (respBody.length) {
respBody.forEach(resp => {
resp[parentOcidName] = parentOcidVal
});
} else {
respBody[parentOcidName] = parentOcidVal
}
}
callback(respBody);
});
});
// Create signature
signature.sign(request, {
key: OracleConfig.privateKey,
keyId: [OracleConfig.tenancyId, OracleConfig.userId, OracleConfig.keyFingerprint].join('/'),
headers: ["host", "date", "(request-target)"]
});
var oldAuthHead = request.getHeader("Authorization");
var newAuthHead = oldAuthHead.replace("Signature ", "Signature version=\"1\",");
request.setHeader("Authorization", newAuthHead);
var requestToWrite = (body === undefined ? '': body);
request.write(requestToWrite);
request.end();
}
body = body || "";
var shaObj = new jsSHA("SHA-256", "TEXT");
shaObj.update(body);
req.setHeader("Content-Length", body.length);
req.setHeader("x-content-sha256", shaObj.getHash('B64'));
headersToSign = headersToSign.concat([
"content-type",
"content-length",
"x-content-sha256"
]);
}
httpSignature.sign(req, {
key: auth.privateKey,
keyId: apiKeyId,
headers: headersToSign
});
var newAuthHeaderValue =
req.getHeader("Authorization").replace("Signature ", "Signature version=\"1\",");
req.setHeader("Authorization", newAuthHeaderValue);
};