Mercurial > prosody-modules
annotate mod_private_adhoc/mod_private_adhoc.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 |
parents | deb79c2357bb |
children |
rev | line source |
---|---|
1461
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
1 -- Prosody IM |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
4 -- |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
7 -- |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
8 |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
9 -- Module by Thomas Raschbacher 2014 |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
10 -- lordvan@lordvan.com |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
11 |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
12 module:depends"adhoc"; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
13 local dataforms_new = require "util.dataforms".new; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
14 local st = require "util.stanza"; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
15 local jid_split = require "util.jid".split; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
16 |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
17 local private_storage = module:open_store("private"); |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
18 |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
19 local private_adhoc_result_layout = dataforms_new{ |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
20 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
21 { name = "privatexmldata", type = "text-multi", label = "Private XML data" }; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
22 }; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
23 |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
24 |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
25 function private_adhoc_command_handler (self, data, state) |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
26 local username, hostname = jid_split(data.from); |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
27 local data, err = private_storage:get(username); |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
28 local dataString = ""; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
29 if not data then |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
30 dataString = "No data found."; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
31 if err then dataString = dataString..err end; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
32 else |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
33 for key,value in pairs(data) do |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
34 dataString = dataString..tostring(st.deserialize(value)):gsub("><",">\n<") |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
35 dataString = dataString.."\n\n"; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
36 end |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
37 end |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
38 return { status = "completed", result= { layout = private_adhoc_result_layout, values = {privatexmldata=dataString.."\n"}} }; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
39 end |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
40 |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
41 local adhoc_new = module:require "adhoc".new; |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
42 local descriptor = adhoc_new("Query private data", "private_adhoc", private_adhoc_command_handler, "local_user"); |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
43 module:add_item ("adhoc", descriptor); |
deb79c2357bb
mod_private_adhoc: initial commit of new module
Thomas Raschbacher <lordvan@lordvan.com>
parents:
diff
changeset
|
44 |