Page 1 of 2
Retrieving authenticated user
Posted: 13 Sep 2016 21:29
by bogr
Hi,
I'm trying to get the authenticated user in a module, but I'm failing. I thought, by reading the doc, it should be possible to do
but I'm getting "undefined". What am I missing?
Re: Retrieving authenticated user
Posted: 13 Sep 2016 22:20
by pah111kg
Hi,
I think you could try the following to log the
http object:
The log file contains than the object as string and you can view the structure and content of
http object.
Re: Retrieving authenticated user
Posted: 13 Sep 2016 22:30
by pah111kg
My proposal does not help much:
... log: [object ZWayHTTP]
Code: Select all
console.log(JSON.stringify(http));
... log: {}
Re: Retrieving authenticated user
Posted: 13 Sep 2016 22:33
by bogr
Aaah, sounds great. Tried it but unfortunately just got empty structure
Code: Select all
[2016-09-13 21:30:44.624] [I] [core] {}
Re: Retrieving authenticated user
Posted: 13 Sep 2016 22:34
by bogr
pah111kg wrote:My proposal does not help much:
... log: [object ZWayHTTP]
Code: Select all
console.log(JSON.stringify(http));
... log: {}
Yes, just tried it as well

Re: Retrieving authenticated user
Posted: 14 Sep 2016 00:06
by PoltoS
http is a built-in JS object that allows to make requests. This is certainly not what you want. May be you can explain a bit in more details?
Re: Retrieving authenticated user
Posted: 14 Sep 2016 08:32
by bogr
Yes, I read the other modules and saw that it is often used to make requests. I want to read the incoming request on the server side. E.g if the client issues the command:
Code: Select all
curl -u user_1:pwd_1 http://host:8083/ZAutomation/api/v1/devices/InvertSwitch22/command/on
I'd like to retreive the "user_1" from the client call - in my module on the server side. Or if this is impossible I'd like to retreive some custom headers - so if the client issues the call:
Code: Select all
curl -u user_1:pwd_1 -H "custom_user_header: user_name" http://localhost:8083/ZAutomation/api/v1/devices/InvertSwitch22/command/on
I'd like to retreive, on the server side, the value of "custom_user_header" by using something like "http.request.headers.custom_user_header".
Re: Retrieving authenticated user
Posted: 17 Sep 2016 01:50
by PoltoS
Please look in sources. request object exists in some scopes, but not in all handlers
Re: Retrieving authenticated user
Posted: 18 Sep 2016 23:50
by bogr
Yes, I've looked in the sources, but is there any doc of the "flow" (client -> server), i.e. which handlers etc that are run when a client call is issued? I can see that there is some logic regarding the request object in e.g. WebserverRequestRouter.js, AuthController.js etc, but the call sequence is quite hard to grasp.
Re: Retrieving authenticated user
Posted: 23 Sep 2016 19:26
by PoltoS
That's true, it is not easy to understand. put an exception (like a = 0/0;) in any place and you will cee traceback
Unfortunatelly we have no good guide on the backend, so you have to look into sources ;( Hopefully they are available