feat(mod_auth_token): add support for 'previd' query param

The 'previd' query parameter will be use to match user id of the session
being resumed when the smacks module and token authentication are
enabled in Prosody. Otherwise user gets new random id every time and
this doesn't work with the smacks module.
This commit is contained in:
paweldomas 2020-03-09 13:50:12 -05:00 committed by Paweł Domas
parent 582d4aff1c
commit 4dc10e82f1
1 changed files with 15 additions and 2 deletions

View File

@ -6,6 +6,7 @@ local generate_uuid = require "util.uuid".generate;
local new_sasl = require "util.sasl".new;
local sasl = require "util.sasl";
local token_util = module:require "token/util".new(module);
local sessions = prosody.full_sessions;
-- no token configuration
if token_util == nil then
@ -25,6 +26,10 @@ function init_session(event)
if query ~= nil then
local params = formdecode(query);
session.auth_token = query and params.token or nil;
-- previd is used together with https://modules.prosody.im/mod_smacks.html
-- the param is used to find resumed session and re-use anonymous(random) user id
-- (see get_username_from_token)
session.previd = query and params.previd or nil;
-- The room name and optional prefix from the bosh query
session.jitsi_bosh_query_room = params.room;
@ -75,6 +80,13 @@ function provider.get_sasl_handler(session)
if (customUsername) then
self.username = customUsername;
elseif (session.previd ~= nil) then
for _, session1 in pairs(sessions) do
if (session1.resumption_token == session.previd) then
self.username = session1.username;
break;
end
end
else
self.username = message;
end
@ -95,10 +107,11 @@ local function anonymous(self, message)
local result, err, msg = self.profile.anonymous(self, username, self.realm);
if result == true then
if (self.username == nil) then
self.username = username;
end
return "success";
else
return "failure", err, msg;
end
end