Comparison

mod_http_oauth2/mod_http_oauth2.lua @ 4258:cc712899becd

mod_http_oauth2: Unpack event object to improve readability
author Kim Alvefur <zash@zash.se>
date Sat, 21 Nov 2020 16:36:44 +0100
parent 4257:145e8e8a247a
child 4259:721b528c01e1
comparison
equal deleted inserted replaced
4257:145e8e8a247a 4258:cc712899becd
173 end 173 end
174 return grant_handler(params); 174 return grant_handler(params);
175 end 175 end
176 176
177 local function handle_authorization_request(event) 177 local function handle_authorization_request(event)
178 if not event.request.headers.authorization then 178 local request, response = event.request, event.response;
179 event.response.headers.www_authenticate = string.format("Basic realm=%q", module.host.."/"..module.name); 179 if not request.headers.authorization then
180 response.headers.www_authenticate = string.format("Basic realm=%q", module.host.."/"..module.name);
180 return 401; 181 return 401;
181 end 182 end
182 local user = check_credentials(event.request); 183 local user = check_credentials(request);
183 if not user then 184 if not user then
184 return 401; 185 return 401;
185 end 186 end
186 if not event.request.url.query then 187 if not request.url.query then
187 event.response.headers.content_type = "application/json"; 188 response.headers.content_type = "application/json";
188 return oauth_error("invalid_request"); 189 return oauth_error("invalid_request");
189 end 190 end
190 local params = http.formdecode(event.request.url.query); 191 local params = http.formdecode(request.url.query);
191 if not params then 192 if not params then
192 return oauth_error("invalid_request"); 193 return oauth_error("invalid_request");
193 end 194 end
194 local response_type = params.response_type; 195 local response_type = params.response_type;
195 local response_handler = response_type_handlers[response_type]; 196 local response_handler = response_type_handlers[response_type];
196 if not response_handler then 197 if not response_handler then
197 event.response.headers.content_type = "application/json"; 198 response.headers.content_type = "application/json";
198 return oauth_error("unsupported_response_type"); 199 return oauth_error("unsupported_response_type");
199 end 200 end
200 return response_handler(params, jid.join(user, module.host)); 201 return response_handler(params, jid.join(user, module.host));
201 end 202 end
202 203