Friends, please help me figure it out. In the description of the task there is an instruction how to edit some entry on the server. Here is the instruction:
To edit a task, you need to transfer to POST, in addition to the editable fields themselves, a special token (use the string "beejee" as the value of this field) and the additional parameter signature "signature".
To generate a signature you need:
- collect all fields sent to POST, including token (except the field signature itself),
- Only editable fields can be sent + token + signature
- sort alphabetically all fields except token (the token field must be last),
- perform URL encoding of request parameters (name parameters and parameter values), encoding is performed according to RFC 3986 standard (for example, the string "example@example.com" is encoded in "example% 40example.com")
- collect sorted URL-encoded fields into one query string (params_string), the separator between the parameter name and its value is the symbol "=", between different parameters the symbol "&" (for example, status = 0 & text = SomeText & token = beejee). We remind you that the parameters must be encoded according to the standard RFC 3986,
- calculate the md5 hash from the URL-encoded query string (md5 (params_string)) and send this md5 hash in the 'signature' field in POST along with other parameters
That's what did
function patchCard(id, newData) { const { text, status } = newData; const bodyWithoutSignature = "status=" + (status ? encodeURIComponent(statusReady) : encodeURIComponent(statusNotReady)) + "&text=" + encodeURIComponent(text) + "&token=" + encodeURIComponent(token); const md5Hash = md5(bodyWithoutSignature); const body = bodyWithoutSignature + "&signature=" + encodeURIComponent(md5Hash); const query = baseURL + "/edit/" + id; const requestOptions = { method: "POST", body: body }; return fetch(query, requestOptions).then(handleResponse); } From the server comes status OK, but nothing is being edited. Please help.
PS In the above code I am trying to change the text and status fields on the server
encodeURIComponent(md5Hash). But I do not think that the problem is this. - Stepan Kasyanenko