Project

General

Profile

How to get session id in a WResource?

Added by Amir Hadzic about 15 years ago

Hello !

I'm serving a custom WResource using server.addResource(&apiService, "/api"); and I need to get the session id when a user sends a request to /api. How could I do this ?

Thank you!


Replies (4)

RE: How to get session id in a WResource? - Added by Wim Dumon about 15 years ago

Hello Amir,

Resources added to the server are sessionless. They are always accessible by anyone; this API will simply translate a http GET/POST/... to the specified path to an access to this resource. Normal WResources live within a session, have a randomly assigned URL and are instantiated within the widget tree.

Could you explain what you are trying to do? We're considering to modify how WResources are 'published', but are still deciding on the right approach.

Regards,

Wim.

RE: How to get session id in a WResource? - Added by Amir Hadzic about 15 years ago

Hi,

I'm basically writing a HTTP API and using a WResource to handle API requests. I don't really need that session id, I can generate a random token and send it back to the user when he logs in using the API. Then, he can send it as a parameter in subsequent calls to the API as only registered users can use the API.

There might be a better way to do this and I'm open to any suggestions. I decided to use WResource as I'm sending responses as XML formated messages and with WResource I can set the mime type to XML document.

Best regards,

Amir

RE: How to get session id in a WResource? - Added by Wim Dumon almost 15 years ago

That would indeed be the way to handle API sessions. Wt's session mechanism is currently designed to handle GUI sessions.

Wim.

RE: How to get session id in a WResource? - Added by Amir Hadzic almost 15 years ago

I have "stolen" the code for generating random tokens from /web/Configuration.C (Configuration::generateSessionId()) and I'm using that to generate random tokens when someone logs in using the API. ;)

    (1-4/4)