Hi everyone,
So far, It seems ns_base64encode generates a different hash key, and the colon
is the problem somehow.
A valid request from Postman or CURL, has the following Authorization block
within it :
Authorization {Basic
HGTRFHTYhththtyhotyhtyjotjytjojg956456346n64ui5n4436346nu4y4iuyn4iutGRENDM3OWQwNmFkMWsFmNg==}
Meaning the authorization hash is:
HGTRFHTYhththtyhotyhtyjotjytjojg956456346n64ui5n4436346nu4y4iuyn4iutGRENDM3OWQwNmFkMWsFmNg==
While the Authorization block generated by [ns_base64encode] is:
Authorization {Basic
HGTRFHTYhththtyhotyhtyjotjytjojg956456346n64ui5n4436346nu4y4}
So, it’s only the first part.
HGTRFHTYhththtyhotyhtyjotjytjojg956456346n64ui5n4436346nu4y4
and the last part, after ":” has been missing (i.e. password)
iuyn4iutGRENDM3OWQwNmFkMWsFmNg==
However, the same credentials were used to generate the 64 bits hash key
encoded.
set req_headers [ns_set create]
ns_set update $req_headers Authorization "Basic [ns_base64encode
Afrewf564DFSFSF54jgnfhgGDGdfRGRT43:7584fjhfjhf84jkrugrefAFFD9449474]"
My guess is that [ns_base64encode] breaks in the colon char, and encodes only
the first part as a 64 bits hash key.
How would the entire string be encode as a 64 bits hash then?
How would the proc ns_base64encode support colon “:" (if the colon is the
problem actually)?
p.s. logs are attached bellow.
Best wishes,
I
A valid request from Postman or CURL, contains the entire 64 bits hash key
encoded
[23/Feb/2021:15:59:08][23531.7efbf356f700][-conn:qonteo:default:1:0-] Notice:
HEADER
: t0
[23/Feb/2021:15:59:08][23531.7efbf356f700][-conn:qonteo:default:1:0-] Notice:
HEADERS 11
[23/Feb/2021:15:59:08][23531.7efbf356f700][-conn:qonteo:default:1:0-] Notice:
Host dashboard.qonteo.com X-Real-IP 187.127.207.76 Connection close
Content-Length 454 Authorization {Basic
HGTRFHTYhththtyhotyhtyjotjytjojg956456346n64ui5n4436346nu4y4iuyn4iutGRENDM3OWQwNmFkMWsFmNg==
User-Agent PostmanRuntime/7.26.8 Accept */* Cache-Control no-cache
Postman-Token 6bd5b753-bc8e-4447-bc85-155f517d6c72 Content-Type
{multipart/form-data;
boundary=--------------------------494740493183890794196511} Cookie
{ad_locale="es_ES";
ad_session_id="34040084%2c0%2c0%2c1614106611%20{362%201614107811%201133CEC432ACA1B0529F80D7603EFD5D38289E85}”}
The request from Naviserver, contains a different Authorization 64 bits hash
key encoded. The has key is only correspondent to the first part of the
authorization (i.e. username).
[23/Feb/2021:15:58:01][1207.7efbb67fc700][-conn:qonteo:default:3:3251-] Notice:
HEADER
: t0
[23/Feb/2021:15:58:01][1207.7efbb67fc700][-conn:qonteo:default:3:3251-] Notice:
HEADERS 6
[23/Feb/2021:15:58:01][1207.7efbb67fc700][-conn:qonteo:default:3:3251-] Notice:
Host dashboard.qonteo.com X-Real-IP 192.199.241.132 Connection close
Content-Length 178 Authorization {Basic
HGTRFHTYhththtyhotyhtyjotjytjojg956456346n64ui5n4436346nu4y4} User-Agent
NaviServer/4.99.19
> On Raj. 11, 1442 AH, at 16:08, Iuri de Araujo Sampaio <[email protected]> wrote:
>
> So far, I've found a previous post, from myself :-), regarding quite the same
> problem.
>
> https://www.mail-archive.com/[email protected]/msg03818.html
>
> <https://www.mail-archive.com/[email protected]/msg03818.html>
>
> >
> > Ok, now add some Authorization. As defined by RFC 7617, one has to add an
> > Authorization request header field with user:id:password encoded in base64.
> > % set h [ns_set create]
> > % ns_set update $h Authorization "Basic [ns_base64encode guest:guest]"
> > % ns_http run -headers $h https://jigsaw.w3.org/HTTP/Basic/
> > <https://jigsaw.w3.org/HTTP/Basic/>
> > <https://jigsaw.w3.org/HTTP/Basic/ <https://jigsaw.w3.org/HTTP/Basic/>>
>
>
> However, I’m still having a hard time to figure out what would be the
> replacement of the following NodeJS sample for a Basic Auth header on
> Naviserver, proc
> ns_http
>
>
> NodeJS sample
>
> ...
> axios
> .post(url, new URLSearchParams(messageBody), {
> auth: {
> username: authSID,
> password: authToken
> }
> })
>
> ...
>
>
>
> TCL Sample
>
> ...
> set req_headers [ns_set create]
> ns_set update $req_headers Authorization "Basic [ns_base64encode
> ${username}:${token}]"
>
> set data [list]
> lappend "[ns_urlencode To]=[ns_urlencode whatsapp:+55454545571]"
> lappend "[ns_urlencode From]=[ns_urlencode whatsapp:+14155238886]"
> lappend "[ns_urlencode Body]=[ns_urlencode \"Your Yummy Cupcakes Company
> order of 1 dozen frosted cupcakes has shipped and should be delivered\"]"
>
>
> set res [ns_http run -method POST -headers $req_headers -body $data $url]
> ns_log Notice "RES2 $res"
>
>
>
> Based on this TCL sample, it returns 401 , meaning authentication step had
> failure.
>
>
> 22/Feb/2021:16:07:21][1207.7efbb6ffd700][-conn:qonteo:default:2:1647-]
> Notice: RES2 status 401 time 0:203450 headers d5 body {{"code": 20003,
> "detail": "", "message": "Authenticate", "more_info":
> "https://www.twilio.com/docs/errors/20003
> <https://www.twilio.com/docs/errors/20003>", "status": 401}} https
> {sslversion TLSv1.2 cipher ECDHE-RSA-AES128-GCM-SHA256}
>
>
>
>
> Best wishes,
> I
>
>
>
>
>> On Raj. 10, 1442 AH, at 20:14, Iuri de Araujo Sampaio <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> Hello there,
>> I’m trying to rewrite a CURL request to Naviserver.
>>
>> curl
>> 'https://api.twilio.com/2010-04-01/Accounts/ACe13c882f57e87c4b4db37/Messages.json
>>
>> <https://api.twilio.com/2010-04-01/Accounts/ACe13c882f57e87c4b4db37/Messages.json>'
>> -X POST \
>> --data-urlencode 'To=whatsapp:+5511998865465' \
>> --data-urlencode 'From=whatsapp:+14155238886' \
>> --data-urlencode 'Body=Your Yummy Cupcakes Company order of 1 dozen frosted
>> cupcakes has shipped and should be delivered on July 10, 2019. Details:
>> http://www.yummycupcakes.com/' <http://www.yummycupcakes.com/'> \
>> -u [Authkey]:[AuthToken]
>>
>>
>> man url
>> -u, --user <user:password>
>> Specify the user name and password to use for server
>> authentication. Overrides -n, --netrc and --netrc-optional.
>>
>> If you simply specify the user name, curl will prompt for a
>> password.
>> …
>>
>>
>>
>> So basically, data-urlencode becomes posta_data. How could -u argument can
>> be rewritten to [ns_http run …] arguments
>>
>>
>> set post_data [list]
>> lappend "[ns_urlencode to]=[ns_urlencode whatsapp:+5511998865465]"
>> lappend "[ns_urlencode From]=[ns_urlencode whatsapp:+14155238886]"
>> lappend "[ns_urlencode Body]=[ns_urlencode \"Your Yummy Cupcakes Company
>> order of 1 dozen frosted cupcakes has shipped and should be deli\
>> vered\"]"
>>
>> set url
>> "https://api.twilio.com/2010-04-01/Accounts/ACe13c431f82f57e87c4b4db37/Messages.json
>>
>> <https://api.twilio.com/2010-04-01/Accounts/ACe13c431f82f57e87c4b4db37/Messages.json>"
>>
>> set res [ns_http run -method POST -headers $req_headers -body $post_data
>> $url]
>> ns_log Notice "RES2 $res"
>>
>>
>>
>> I was looking for references in the documentation, however I haven’t found
>> any matches. What's the replacement of curl -u in ns_http?
>>
>> References:
>> https://naviserver.sourceforge.io/n/naviserver/files/ns_http.html
>> <https://naviserver.sourceforge.io/n/naviserver/files/ns_http.html>
>>
>>
>> Best wishes,
>> I
>
> _______________________________________________
> naviserver-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/naviserver-devel
_______________________________________________
naviserver-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/naviserver-devel