mod_auth_oauth_external: Allow different username in PLAIN vs final JID
authorKim Alvefur <zash@zash.se>
Wed, 10 May 2023 13:52:31 +0200
changeset 5444 82a14082be3f
parent 5443 721f79ac88d8
child 5445 533808db6c18
mod_auth_oauth_external: Allow different username in PLAIN vs final JID Mastodon for example having email addresses usernames in login, but a different username in the service itself. Thanks to @tcit@social.tcit.fr for the pointer to a usable validation endpoint for Mastodon, allowing this to be tested.
mod_auth_oauth_external/mod_auth_oauth_external.lua
--- a/mod_auth_oauth_external/mod_auth_oauth_external.lua	Wed May 10 13:45:28 2023 +0200
+++ b/mod_auth_oauth_external/mod_auth_oauth_external.lua	Wed May 10 13:52:31 2023 +0200
@@ -71,9 +71,12 @@
 				return false, nil;
 			end
 			local response = json.decode(ret.body);
-			if type(response) ~= "table" or (response[username_field]) ~= username then
+			if type(response) ~= "table" then
+				return false, nil, nil;
+			elseif type(response[username_field]) ~= "string" then
 				return false, nil, nil;
 			end
+			self.username = jid.escape(response[username_field]);
 			self.token_info = response;
 			return true, true;
 		end