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


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 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 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>
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>
> 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/ to test my API request.
>
> Thank you
> _______________________________________________
> 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
>
_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to