Software /
code /
prosody-modules
Annotate
mod_log_json/mod_log_json.lua @ 5193:2bb29ece216b
mod_http_oauth2: Implement stateless dynamic client registration
Replaces previous explicit registration that required either the
additional module mod_adhoc_oauth2_client or manually editing the
database. That method was enough to have something to test with, but
would not probably not scale easily.
Dynamic client registration allows creating clients on the fly, which
may be even easier in theory.
In order to not allow basically unauthenticated writes to the database,
we implement a stateless model here.
per_host_key := HMAC(config -> oauth2_registration_key, hostname)
client_id := JWT { client metadata } signed with per_host_key
client_secret := HMAC(per_host_key, client_id)
This should ensure everything we need to know is part of the client_id,
allowing redirects etc to be validated, and the client_secret can be
validated with only the client_id and the per_host_key.
A nonce injected into the client_id JWT should ensure nobody can submit
the same client metadata and retrieve the same client_secret
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 03 Mar 2023 21:14:19 +0100 |
parent | 4974:807007913f67 |
rev | line source |
---|---|
4974
807007913f67
mod_log_json: Prefer native Lua table.pack over Prosody util.table one
Kim Alvefur <zash@zash.se>
parents:
4462
diff
changeset
|
1 local pack = table.pack or require "util.table".pack; |
3732 | 2 local json = require "util.json"; |
3 local array = require "util.array"; | |
4 local datetime = require "util.datetime".datetime; | |
3746 | 5 local socket = require "socket"; |
3732 | 6 |
7 module:set_global(); | |
8 | |
9 local function sink_maker(config) | |
3746 | 10 local send = function () end |
11 if config.filename then | |
12 local logfile = io.open(config.filename, "a+"); | |
13 logfile:setvbuf("no"); | |
14 function send(payload) | |
15 logfile:write(payload, "\n"); | |
16 end | |
17 elseif config.udp_host and config.udp_port then | |
18 local conn = socket.udp(); | |
3748
27abf3b6819a
mod_log_json: Use correct method to specify remote endpoint
Kim Alvefur <zash@zash.se>
parents:
3747
diff
changeset
|
19 conn:setpeername(config.udp_host, config.udp_port); |
3746 | 20 function send(payload) |
21 conn:send(payload); | |
22 end | |
23 end | |
4462
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
24 local format = require "util.format".format; |
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
25 local do_format = config.formatted_as or false; |
3732 | 26 return function (source, level, message, ...) |
27 local args = pack(...); | |
28 for i = 1, args.n do | |
29 if args[i] == nil then | |
30 args[i] = json.null; | |
31 elseif type(args[i]) ~= "string" or type(args[i]) ~= "number" then | |
32 args[i] = tostring(args[i]); | |
33 end | |
34 end | |
35 args.n = nil; | |
36 local payload = { | |
37 datetime = datetime(), | |
38 source = source, | |
39 level = level, | |
40 message = message, | |
41 args = array(args); | |
42 }; | |
4462
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
43 if do_format then |
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
44 payload[do_format] = format(message, ...) |
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
45 end |
3746 | 46 send(json.encode(payload)); |
3732 | 47 end |
48 end | |
49 | |
3758
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
50 function module.unload() |
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
51 -- deregister |
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
52 require"core.loggingmanager".register_sink_type("json", nil); |
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
53 end |
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
54 |
3732 | 55 require"core.loggingmanager".register_sink_type("json", sink_maker); |