Authenticating before sending requests

I am trying to connect and pull data from a url and I have no idea how to even begin for the login/authentication part. This will pull data from a url via HTTP POST
I was hoping someone here with the correct know how can help me out.

This is what I have from the docs:
image

It gives some java methods for calculating time, md5 but not sure what do with them.
The signature string is:

"POST\nmBAcWORUK93FBOz6jsAuqw==\napplication/json\nFri, 26 Jul 2019 
06:00:46 GMT\n/v1/api/userStationList"

Even if someone can help me convert it to javascript code so that it will just work inside a normal function (if possible)

How do you convert a image to javascript,? You need to paste code, then someone may help. You may find someone who wishes to waste their time coping it from your image, but you will find more will help if you make life easier for them to help.

Good point, let me add it here:

Authorization = "API " + KeyId + ":" + Sign
Sign = base64(HmacSHA1(KeySecret,
VERB + "\n"
+ Content-MD5 + "\n"
+ Content-Type + "\n"
+ Date + "\n"
+ CanonicalizedResource))

Authorization Field calculation example
If the KeyId is: 2424 and the KeySecret is: 6680182547, the following method can be used to
calculate the signature sign
Request:

POST /v1/api/userStationList
Content-MD5: mBAcWORUK93FBOz6jsAuqw==
Content-Type: application/json
Date: Fri, 26 Jul 2019 06:00:46 GMT
Authorization: API 2424: ForAqMkym0v7R94RSU0rRqpEkf0=
Body:{"userId":"1145611319416590338"}

Note: There is no "Body:" in the post content sent

The signature string is:

" POST\nmBAcWORUK93FBOz6jsAuqw==\napplication/json\nFri, 26 Jul 2019
06:00:46 GMT\n/v1/api/userStationList"

Authorization Calculation
Because Authorization = "API "+ KeyId + ":" + Signa, the final Authorization is “API 2424:
/2Np3q5h846q9cWEFUNtbL+G7H8=”,
Then add the Authorization header to form the final message that needs to be sent:

POST /v1/api/userStationList
Content-MD5: mBAcWORUK93FBOz6jsAuqw==
Content-Type: application/json
Date: Fri, 26 Jul 2019 06:00:46 GMT
Authorization: API 2424:/2Np3q5h846q9cWEFUNtbL+G7H8=
{"userId":"1145611319416590338"}

I am guessing I need to pass those headers above to each request but I have no idea how to calculate them.

I am unsure of syntax for the sha1 part of the code.
But there are node for base64 and crypto.js sha1
https://flows.nodered.org/node/node-red-contrib-checksum
https://flows.nodered.org/node/node-red-node-base64

They provide this java method, not sure it can be just plugged into node-red?

public static String HmacSHA1Encrypt(String encryptText, String 
keySecret) throws Exception 
{ 
 byte[] data= keySecret.getBytes("UTF-8"); 

 SecretKey secretKey = new SecretKeySpec(data, "HmacSHA1"); 

 Mac mac = Mac.getInstance("HmacSHA1"); 

 mac.init(secretKey); 
 byte[] text = encryptText.getBytes("UTF-8"); 

 byte[] result = mac.doFinal(text); 
 return Base64.encodeBase64String(result); 
} 

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.