Pārlūkot izejas kodu

Fires event before setting username, allows listeners to override it.

This is a hook to override the username that will be used when authenticating token users (which are using anonymous login with auto-generated username).
j8
damencho 8 gadus atpakaļ
vecāks
revīzija
cc79b073f0
1 mainītis faili ar 12 papildinājumiem un 3 dzēšanām
  1. 12
    3
      resources/prosody-plugins/mod_auth_token.lua

+ 12
- 3
resources/prosody-plugins/mod_auth_token.lua Parādīt failu

@@ -58,7 +58,18 @@ end
58 58
 function provider.get_sasl_handler(session)
59 59
 
60 60
 	local function get_username_from_token(self, message)
61
-        return token_util:process_and_verify_token(session);
61
+        local res = token_util:process_and_verify_token(session);
62
+
63
+        local customUsername
64
+            = prosody.events.fire_event("pre-jitsi-authentication", session);
65
+
66
+        if (customUsername) then
67
+            self.username = customUsername;
68
+        else
69
+            self.username = message;
70
+        end
71
+
72
+        return res;
62 73
 	end
63 74
 
64 75
 	return new_sasl(host, { anonymous = get_username_from_token });
@@ -73,8 +84,6 @@ local function anonymous(self, message)
73 84
 	-- This calls the handler created in 'provider.get_sasl_handler(session)'
74 85
 	local result, err, msg = self.profile.anonymous(self, username, self.realm);
75 86
 
76
-	self.username = username;
77
-
78 87
 	if result == true then
79 88
 		return "success";
80 89
 	else

Notiek ielāde…
Atcelt
Saglabāt