I have some API that must be signed with request params hash. For example I have 2 params - login and password in request params. So I need to add the param checksum that is calculated with login and password fields hash.
How can I implement it? Now when I try to calculate it, I have the self-dependency error.
login = test
password = test
somefield = lalala
checksum = md5([login][password][somefield]) <- here is dynamic evaluation
The self-dependency error is shown because it actually tries to evaluate the full URL to get one of the other parameters. That's probably something that needs to be fixed in Paw.
However, you can simply ignore the warning, as it still works. Here is an example:
In your example, the checksum is 8bc22595f820ff1612fd16294c02359a
which is the expected result.
Update: if you want to do that with JavaScript code, here's an example.
function evaluate(context) {
var url = context.getCurrentRequest().url;
var query = url.split('?')[1];
var fragments = query.split('&');
var login, password, somefield;
for (var i in fragments) {
var keyvalue = fragments[i].split('=');
if (keyvalue[0] == "login") {
login = keyvalue[1];
} else if (keyvalue[0] == "password") {
password = keyvalue[1];
} else if (keyvalue[0] == "somefield") {
somefield = keyvalue[1];
}
}
// you can now compute whatever hash you want with these values
// the self-dependency error will be shown but it should work
return "" + login + "-" + password + "-" + somefield;
};
To calculate MD5 hashes with JS, you'll need to include a 3rd party library. That can be more easily (and more cleanly) done via npm. See how we are managing dependencies in other Extensions: https://github.com/LuckyMarmot/Paw-PythonRequestsCodeGenerator
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With