Quellcode durchsuchen

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.
master
paweldomas vor 5 Jahren
Ursprung
Commit
4dc10e82f1
1 geänderte Dateien mit 15 neuen und 2 gelöschten Zeilen
  1. 15
    2
      resources/prosody-plugins/mod_auth_token.lua

+ 15
- 2
resources/prosody-plugins/mod_auth_token.lua Datei anzeigen

@@ -6,6 +6,7 @@ local generate_uuid = require "util.uuid".generate;
6 6
 local new_sasl = require "util.sasl".new;
7 7
 local sasl = require "util.sasl";
8 8
 local token_util = module:require "token/util".new(module);
9
+local sessions = prosody.full_sessions;
9 10
 
10 11
 -- no token configuration
11 12
 if token_util == nil then
@@ -25,6 +26,10 @@ function init_session(event)
25 26
 	if query ~= nil then
26 27
         local params = formdecode(query);
27 28
         session.auth_token = query and params.token or nil;
29
+        -- previd is used together with https://modules.prosody.im/mod_smacks.html
30
+        -- the param is used to find resumed session and re-use anonymous(random) user id
31
+        -- (see get_username_from_token)
32
+        session.previd = query and params.previd or nil;
28 33
 
29 34
         -- The room name and optional prefix from the bosh query
30 35
         session.jitsi_bosh_query_room = params.room;
@@ -75,6 +80,13 @@ function provider.get_sasl_handler(session)
75 80
 
76 81
         if (customUsername) then
77 82
             self.username = customUsername;
83
+        elseif (session.previd ~= nil) then
84
+            for _, session1 in pairs(sessions) do
85
+                if (session1.resumption_token == session.previd) then
86
+                    self.username = session1.username;
87
+                    break;
88
+                end
89
+        	end
78 90
         else
79 91
             self.username = message;
80 92
         end
@@ -95,10 +107,11 @@ local function anonymous(self, message)
95 107
 	local result, err, msg = self.profile.anonymous(self, username, self.realm);
96 108
 
97 109
 	if result == true then
98
-		self.username = username;
110
+		if (self.username == nil) then
111
+			self.username = username;
112
+		end
99 113
 		return "success";
100 114
 	else
101
-
102 115
 		return "failure", err, msg;
103 116
 	end
104 117
 end

Laden…
Abbrechen
Speichern