bungle / lua-resty-session

Session library for OpenResty – flexible and secure
BSD 2-Clause "Simplified" License
319 stars 111 forks source link

redis and session id #132

Closed x-077 closed 1 year ago

x-077 commented 3 years ago

Hello,

Im using resty.openidc and they provide an options lifecycle that allow us to manipulate the session in 4 lifecycle options :

lifecycle = {
    on_created = handle_created,
    on_authenticated = handle_authenticated,
    on_regenerated = handle_regenerated
    on_logout = handle_logout
}

handle_created, handle_authenticated, handle_regenerated and handle_logout are methods that take the session as argument.

Example:

local _M = {}
local cjson = require("cjson")

function _M.on_created(session)
    -- ngx.say("jere")

    ngx.log(ngx.INFO, "on_created is -----------> :    --->", cjson.encode({session = session.id }))

    -- ngx.say() 
end

return _M

I would like to keep track of the sessions id of each user but Im not sure how to get it. As indicated in the documentation, by default it is 16 bytes long (raw binary bytes).

How can I convert it to a string ? Is this the appropriate way to get the session id ?

To be clear, I would like to get the same id than in redis (example P-WhIe1pYvzPGio8oQjDpw ) :

127.0.0.1:6379> KEYS *
 1) "users:sessions:P-WhIe1pYvzPGio8oQjDpw"

thanks

bungle commented 2 years ago

Yes, this is a good feature request. I will look at implementing it. Perhaps we need to add something like `session.subject = "user-x" that then get's stored nicely in databases, so that you could delete sessions by user, or limit that user can have just single session at time.

bungle commented 2 years ago

Relates to #131

some0ne2 commented 2 years ago

@bungle Any update onto this? Would require such a feature too. Is there any workaround how to get to the same id as stored inside redis, so I can interact with the redis data directly?

@matth-c3 Have you found a way to get the id?

some0ne2 commented 2 years ago

Bump this, please don't let this library die.

some0ne2 commented 2 years ago

Has anybody a hint for this problem?

bungle commented 1 year ago

The 4.0.0 has store_metadata option that enables collecting the sessions per user. It is to be used with :set_subject("jere") and perhaps :set_audience("my-audience") . Audience can also be set on config level.