Hi Maksym,
Indeed I got it now. And I’m able to replicate your scenario on my end.


Unless there's a bug (i.e. malformed list in the ns_auth assignment), it seems 
ns_set supports only reserved keys for “auth”. So, I believe it’s because NS 
source only assigns default values (basic headers to it). Even because 
documentation points to that direction [1] and [2]

[1] https://naviserver.sourceforge.io/n/naviserver/files/ns_conn.html#4 
<https://naviserver.sourceforge.io/n/naviserver/files/ns_conn.html#4>
[2] https://naviserver.sourceforge.io/n/naviserver/files/ns_set.html#2 
<https://naviserver.sourceforge.io/n/naviserver/files/ns_set.html#2>



So, the question is how do we make NS aware of customs auth headers?

Here it's a situation when we must call the academy within their super powers… 

@Gustaf we need your help, please!



Here it’s a draft that I’ve written to test and confirm your assumption. It was 
supposed to return: 

Authorization {Bearer 
eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eydzdWInOiAnNzA0JywgJ2lhdCc6IDE1OTA1MzAxODZ9.20f471933ae0a9c58d525f4ab0c1eef7adab03f17c3bbe18a00cf30a1ef06948}

but it returns void as yours.  I’m running version 4.99.19  Notice: nsmain: 
NaviServer/4.99.19 (tar-4.99.19) running


Best wishes,
I



ns_log Notice "Running REST upload-image"

    ns_log Notice "AUTH [ns_conn auth]”
    ns_log Notice “ARRAY AUTH [ns_set array [ns_conn auth]]”
    set l_auth [ns_set list [ns_conn auth]]
    ns_log Notice "LIST AUTH $l_auth"
    foreach elem $l_auth {
        ns_log Notice "[ns_set array $elem]"
    }


[21/Nov/2020:17:03:27][29540.7efbf356f700][-conn:qonteo:default:1:7-] Notice: 
Running REST upload-image
[21/Nov/2020:17:03:27][29540.7efbf356f700][-conn:qonteo:default:1:7-] Notice: 
AUTH t4
[21/Nov/2020:17:03:27][29540.7efbf356f700][-conn:qonteo:default:1:7-] Notice: 
LIST AUTH t4 t0 d1 d2 d3
[21/Nov/2020:17:03:27][29540.7efbf356f700][-conn:qonteo:default:1:7-] Notice: 
[21/Nov/2020:17:03:27][29540.7efbf356f700][-conn:qonteo:default:1:7-] Notice: 
Host dashboard.qonteo.com X-Real-IP 186.241.25.44 Connection close 
Content-Length 124783 Authorization {Bearer 
eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eydzdWInOiAnNzA0JywgJ2lhdCc6IDE1OTA1MzAxODZ9.20f471933ae0a9c58d525f4ab0c1eef7adab03f17c3bbe18a00cf30a1ef06948}
 Content-Type application/json User-Agent PostmanRuntime/7.26.5 Accept */* 
Cache-Control no-cache Postman-Token 11c80053-7900-40d9-9a4c-688202241247 
Cookie {ad_locale="es_ES"; 
ad_session_id="14300003%2c0%2c0%2c1605988670%20{451%201605989870%20AD31BFFB853E3AF51C2782F7F62798E155436A99}"}
[21/Nov/2020:17:03:27][29540.7efbf356f700][-conn:qonteo:default:1:7-] Notice: 
site_node__node_id 219402
[21/Nov/2020:17:03:27][29540.7efbf356f700][-conn:qonteo:default:1:7-] Notice: 
permission_p 1
[21/Nov/2020:17:03:27][29540.7efbf356f700][-conn:qonteo:default:1:7-] Notice: 
permission_p 0






> On Rab. II 6, 1442 AH, at 16:27, Maksym Zinchenko <siqsu...@gmail.com> wrote:
> 
> Hello Iuri, I think you misunderstood my question.
> My problem is not to set but to get "ns_set"
> 
> I'm using this: 
> https://naviserver.sourceforge.io/n/naviserver/files/ns_conn.html#4 
>  <https://naviserver.sourceforge.io/n/naviserver/files/ns_conn.html#4>
> 
> When client sends request to my server i want to get authentication method 
> using [ ns_conn auth <> ]
> Here is simple example code:
> ...
> ns_register_proc GET /test_api ::api::test_api
> 
> proc test_api {args} {
> set url [file split [ns_conn url]]
> set api_version [lindex $url 2]
> set resource [lindex $url 3]
> set method [ns_conn method]
> set auth [ns_conn auth]
> 
> puts "AUTHORIZATION: [ns_set array $auth]"
> puts "HEADERS: [ns_set array [ns_conn headers]]"
> ns_respond -status 200 -type "application/txt" -string "OK"
> }
> ...
> 
> This is what i get when use basic, looks good:
> ...
> AUTHORIZATION: AuthMethod Basic Password admin Username admin
> HEADERS: Host dev.testdomain.org <http://dev.testdomain.org/> Accept */* 
> Accept-Encoding {deflate, gzip} Authorization {Basic YWRtaW46YWRtaW4=} 
> User-Agent {Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 
> Firefox/83.0} X-Real-IP 
> xxx.90.xxx.244
> ...
> 
> This is what I get using bearer:
> 
> ...
> AUTHORIZATION: 
> HEADERS: Host dev.testdomain.org <http://dev.testdomain.org/> Accept */* 
> Accept-Encoding {deflate, gzip} Authorization {Bearer aaaaaaaaaaaaaaaa} 
> User-Agent {Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 
> Firefox/83.0} X-Real-IP xxx.90.xxx.244
> 
> ...
> 
> I was expecting [ns_conn auth <>] to return something like: AuthMethod bearer 
> Token aaaaaaaaaaaaaaaa
> 
> 
> 
> 
> 
> 
> 
> On Sat, Nov 21, 2020 at 4:50 PM Iuri de Araujo Sampaio <i...@iurix.com 
> <mailto:i...@iurix.com>> wrote:
> Hello Maksym,
> One can add any custom variable (i.e. Authorization “Bearer …") in the 
> response headers as in: 
> 
> …
> set headers [ns_set new]
> ns_set put $headers "Authorization" "Bearer $token"
>  …
> ns_respond -status $status -type "application/json" -headers $headers -string 
> $response
> ad_script_abort
> 
> 
> That chunk is part of a JWT/login authentication API method. However, that’s 
> very basic, and probably I haven’t understood the actual problem that you are 
> facing.
> 
> Let us know,
> 
> Best wishes,
> I
> 
> 
> 
>> On Rab. II 6, 1442 AH, at 13:59, Maksym Zinchenko <siqsu...@gmail.com 
>> <mailto:siqsu...@gmail.com>> wrote:
>> 
>> Hello, hope you are doing well.
>> I have a little question. Maybe a bug, would be so kind to help me out.
>> According to documentation [ns_conn auth] should return all authorization 
>> headers as a ns_set. 
>> It works fine when using "Basic Authentication scheme", i've seen in the 
>> source code it should work with "Digest"
>> But when im trying to use "Bearer Authentication scheme" or "Custom" it 
>> returns empty ns_set, but i can see Authentication part in [ns_conn headers].
>> 
>> P.S.
>> Im using https://reqbin.com/ <https://reqbin.com/> to test my API request.
>> 
>> Thank you
>> _______________________________________________
>> naviserver-devel mailing list
>> naviserver-devel@lists.sourceforge.net 
>> <mailto:naviserver-devel@lists.sourceforge.net>
>> https://lists.sourceforge.net/lists/listinfo/naviserver-devel 
>> <https://lists.sourceforge.net/lists/listinfo/naviserver-devel>
> 
> _______________________________________________
> naviserver-devel mailing list
> naviserver-devel@lists.sourceforge.net 
> <mailto:naviserver-devel@lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/naviserver-devel 
> <https://lists.sourceforge.net/lists/listinfo/naviserver-devel>
> _______________________________________________
> naviserver-devel mailing list
> naviserver-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/naviserver-devel

_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to