Comparison

mod_rest/mod_rest.lua @ 6273:8ceedc336d0d

Merge update
author Trần H. Trung <xmpp:trần.h.trung@trung.fun>
date Sun, 01 Jun 2025 13:51:38 +0700
parent 6272:ed6fa901cf94
comparison
equal deleted inserted replaced
6263:10a1016d1c3a 6273:8ceedc336d0d
62 auth_type = auth_type and auth_type:lower(); 62 auth_type = auth_type and auth_type:lower();
63 if not (auth_type and auth_data) or not auth_mechanisms:contains(auth_type) then 63 if not (auth_type and auth_data) or not auth_mechanisms:contains(auth_type) then
64 return nil, post_errors.new("noauthz", { request = request }); 64 return nil, post_errors.new("noauthz", { request = request });
65 end 65 end
66 66
67 if auth_type == "basic" then 67 if auth_type == "basic" and module:get_host_type() == "local" then
68 local creds = base64.decode(auth_data); 68 local creds = base64.decode(auth_data);
69 if not creds then 69 if not creds then
70 return nil, post_errors.new("malformauthz", { request = request }); 70 return nil, post_errors.new("malformauthz", { request = request });
71 end 71 end
72 local username, password = string.match(creds, "^([^:]+):(.*)$"); 72 local username, password = string.match(creds, "^([^:]+):(.*)$");
79 end 79 end
80 if not um.test_password(username, module.host, password) then 80 if not um.test_password(username, module.host, password) then
81 return false, post_errors.new("unauthz", { request = request }); 81 return false, post_errors.new("unauthz", { request = request });
82 end 82 end
83 return { username = username; host = module.host }; 83 return { username = username; host = module.host };
84 elseif auth_type == "basic" and module:get_host_type() == "component" then
85 local component_secret = module:get_option_string("component_secret");
86 local creds = base64.decode(auth_data);
87 if creds ~= module.host .. ":" .. component_secret then
88 return nil, post_errors.new("malformauthz", { request = request });
89 end
90 return { host = module.host };
84 elseif auth_type == "bearer" then 91 elseif auth_type == "bearer" then
85 if tokens.get_token_session then 92 if tokens.get_token_session then
86 local token_session, err = tokens.get_token_session(auth_data); 93 local token_session, err = tokens.get_token_session(auth_data);
87 if not token_session then 94 if not token_session then
88 return false, token_session_errors.new(err or "not-authorized", { request = request }); 95 return false, token_session_errors.new(err or "not-authorized", { request = request });