lua-resty-session icon indicating copy to clipboard operation
lua-resty-session copied to clipboard

Is it possible to specify session id to delete a session?

Open kingluo opened this issue 3 years ago • 5 comments

Sometimes the session is not determined from cookie of the current request, and it's necessary to delete a session by specifing the session id, e.g. in SAML protocol, when receiving the logout request from IdP, it need to delete the session which does not belongs to current cookie.

kingluo avatar Aug 08 '22 05:08 kingluo

It is possible to delete sessions that use storage other than cookie. Currently we have no way to maintain a revocation list for sessions that are stored on cookie storage. You can implement is, but it is not provided by the library currently. With server side storages session is gone if you delete the data from server side session storage.

bungle avatar Aug 15 '22 14:08 bungle

@bungle According to my test, the following codes work:

local session = require "resty.session".new({
  storage = "shm"
})
local session_id = session.encoder.encode(id)
session.storage:destroy(session_id)

But such codes are tight coupling with internal implementation. Do you think it's ok to encapsulate such codes into high level API?

kingluo avatar Aug 16 '22 06:08 kingluo

I need this api too. Because of the administrator wants to LOCK and LOGOUT some other users.

GYWang1983 avatar Jan 03 '23 08:01 GYWang1983

@GYWang1983, @kingluo,

I am currently working on 4.0 version of the library. It will come with a lot of stuff. I hope to release it within couple of weeks. I will consider adding some of this admin stuff there, but most likely will happen on the 4.1.0.

The code is currently in here: https://github.com/bungle/lua-resty-session/tree/release/4.0.0

bungle avatar Jan 17 '23 10:01 bungle

@GYWang1983, upgrade to 4.0 and enable store_metadata. Here is quick script for redis storage that I got from co-worker:

echo -n "[YOUR_USER]" | base64 | sed 's/..$//' | xargs -L1 -I '$' redis-cli -a [PWD] --scan --pattern "sessions:*$" | xargs -L1 -I '$' redis-cli -a [PWD] zrange "$" 0 -1 | xargs -I '$' echo 'sessions:session:$' | xargs redis-cli -a [PWD] DEL

bungle avatar Mar 08 '23 12:03 bungle