Comparison

mod_http_oauth2/mod_http_oauth2.lua @ 4276:ec33b3b1136c

mod_http_oauth2: Fix passing OAuth-specific error details Error 'context' isn't preserved when passed this way, that would be the second argument. Fits better in extras anyways.
author Kim Alvefur <zash@zash.se>
date Sat, 28 Nov 2020 21:22:16 +0100
parent 4272:91b951fb3018
child 4340:7cd3b7ec59e9
comparison
equal deleted inserted replaced
4275:bb111148d031 4276:ec33b3b1136c
35 return errors.new({ 35 return errors.new({
36 type = "modify"; 36 type = "modify";
37 condition = "bad-request"; 37 condition = "bad-request";
38 code = err_name == "invalid_client" and 401 or 400; 38 code = err_name == "invalid_client" and 401 or 400;
39 text = err_desc and (err_name..": "..err_desc) or err_name; 39 text = err_desc and (err_name..": "..err_desc) or err_name;
40 context = { oauth2_response = { error = err_name, error_description = err_desc } }; 40 extra = { oauth2_response = { error = err_name, error_description = err_desc } };
41 }); 41 });
42 end 42 end
43 43
44 local function new_access_token(token_jid, scope, ttl) 44 local function new_access_token(token_jid, scope, ttl)
45 local token = tokens.create_jid_token(token_jid, token_jid, scope, ttl); 45 local token = tokens.create_jid_token(token_jid, token_jid, scope, ttl);
240 }); 240 });
241 241
242 local http_server = require "net.http.server"; 242 local http_server = require "net.http.server";
243 243
244 module:hook_object_event(http_server, "http-error", function (event) 244 module:hook_object_event(http_server, "http-error", function (event)
245 local oauth2_response = event.error and event.error.context and event.error.context.oauth2_response; 245 local oauth2_response = event.error and event.error.extra and event.error.extra.oauth2_response;
246 if not oauth2_response then 246 if not oauth2_response then
247 return; 247 return;
248 end 248 end
249 event.response.headers.content_type = "application/json"; 249 event.response.headers.content_type = "application/json";
250 event.response.status_code = event.error.code or 400; 250 event.response.status_code = event.error.code or 400;