So far, I've found a previous post, from myself :-), regarding quite the same 
problem.

https://www.mail-archive.com/naviserver-devel@lists.sourceforge.net/msg03818.html
 
<https://www.mail-archive.com/naviserver-devel@lists.sourceforge.net/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";, "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 <i...@iurix.com> 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
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to