Retrieving authenticated user

Discussions about Z-Way software and Z-Wave technology in general
bogr
Posts: 179
Joined: 16 Nov 2015 22:46

Retrieving authenticated user

Post 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

Code: Select all

http.request.auth
but I'm getting "undefined". What am I missing?

pah111kg
Posts: 25
Joined: 02 Sep 2016 18:49

Re: Retrieving authenticated user

Post by pah111kg »

Hi,

I think you could try the following to log the http object:

Code: Select all

console.log(JSON.stringify(http);
The log file contains than the object as string and you can view the structure and content of http object.

pah111kg
Posts: 25
Joined: 02 Sep 2016 18:49

Re: Retrieving authenticated user

Post by pah111kg »

My proposal does not help much:

Code: Select all

console.log(http);
... log: [object ZWayHTTP]

Code: Select all

console.log(JSON.stringify(http));
... log: {}

bogr
Posts: 179
Joined: 16 Nov 2015 22:46

Re: Retrieving authenticated user

Post 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] {}

bogr
Posts: 179
Joined: 16 Nov 2015 22:46

Re: Retrieving authenticated user

Post by bogr »

pah111kg wrote:My proposal does not help much:

Code: Select all

console.log(http);
... log: [object ZWayHTTP]

Code: Select all

console.log(JSON.stringify(http));
... log: {}

Yes, just tried it as well :o

User avatar
PoltoS
Posts: 5705
Joined: 26 Jan 2011 19:36

Re: Retrieving authenticated user

Post 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?

bogr
Posts: 179
Joined: 16 Nov 2015 22:46

Re: Retrieving authenticated user

Post 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".

User avatar
PoltoS
Posts: 5705
Joined: 26 Jan 2011 19:36

Re: Retrieving authenticated user

Post by PoltoS »

Please look in sources. request object exists in some scopes, but not in all handlers

bogr
Posts: 179
Joined: 16 Nov 2015 22:46

Re: Retrieving authenticated user

Post 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.

User avatar
PoltoS
Posts: 5705
Joined: 26 Jan 2011 19:36

Re: Retrieving authenticated user

Post 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

Post Reply