Getting user session from jid

Hi there,

we have code like this (inspired by: https://github.com/nvonahsen/jitsi-token-moderation-plugin/blob/master/mod_token_moderation.lua#L35):

module:hook('muc-room-created', function(event)
    local _set_affiliation = room.set_affiliation;
    room.set_affiliation = function(room, actor, jid, affiliation, reason)
        if actor == "token_plugin" then
            return _set_affiliation(room, true, jid, affiliation, reason);
        else
            -- I want to get the session information here
            return _set_affiliation(room, actor, jid, affiliation, reason);
        end
    end;
end);

How could we access session object (or origin) for the given jid in the line with the comment -- I want to get the session information here?

Thanks!

To address the above question, we ended up storing the token at login in the store (https://prosody.im/doc/developers/moduleapi#storage) and are then retrieving it from the store in the above code and authorize the user before setting the affiliation for him.

EDIT
For the sake of completeness, we remove the token from the store once the user leaves the room - in the muc-occupant-left event.