Calculation of the dynamic value of a parameter depending on the parameters in Paw

I have an API that needs to be signed with a params hash of the request. For example, I have 2 parameters - login and password in the request parameters. Therefore, I need to add the param checksum, which is calculated using a hash of the login and password fields.

How can I implement it? Now, when I try to calculate it, I have a self-dependency error.

login = test
password = test
somefield = lalala
checksum = md5([login][password][somefield]) <- here is dynamic evaluation
+4
source share
1 answer

A self-reliance error is shown because it is actually trying to evaluate the full URL to get one of the other parameters. Perhaps something needs to be fixed in Paw.

However, you can simply ignore the warning as it still works. Here is an example:

Calculate a MD5 digest of URL parameters with Paw

8bc22595f820ff1612fd16294c02359a, .

: JavaScript-, .

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;
};

Use a JavaScript script to extract request parameters in Paw

MD5 JS, . ( ) npm. , : https://github.com/LuckyMarmot/Paw-PythonRequestsCodeGenerator

+10

All Articles