Mercurial > prosody-modules
annotate mod_support_contact/mod_support_contact.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 | 7dbde05b48a9 |
children |
rev | line source |
---|---|
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 -- mod_support_contact.lua |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 -- |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 -- Config options: |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 -- support_contact = "support@hostname"; -- a JID |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- support_contact_nick = "Support!"; -- roster nick |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- support_contact_group = "Users being supported!"; -- the roster group in the support contact's roster |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local host = module:get_host(); |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 |
986
8b1250df82e8
mod_support_contact: Use module:get_option_string()
Kim Alvefur <zash@zash.se>
parents:
777
diff
changeset
|
10 local support_contact = module:get_option_string("support_contact", "support@"..host); |
8b1250df82e8
mod_support_contact: Use module:get_option_string()
Kim Alvefur <zash@zash.se>
parents:
777
diff
changeset
|
11 local support_contact_nick = module:get_option_string("support_contact_nick", "Support"); |
8b1250df82e8
mod_support_contact: Use module:get_option_string()
Kim Alvefur <zash@zash.se>
parents:
777
diff
changeset
|
12 local support_contact_group = module:get_option_string("support_contact_group", "Users"); |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 if not(support_contact and support_contact_nick) then return; end |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local rostermanager = require "core.rostermanager"; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 local jid_split = require "util.jid".split; |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
18 local st = require "util.stanza"; |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 module:hook("user-registered", function(event) |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 module:log("debug", "Adding support contact"); |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 local groups = support_contact_group and {[support_contact_group] = true;} or {}; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 local node, host = event.username, event.host; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 local jid = node and (node..'@'..host) or host; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 local roster; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
29 roster = rostermanager.load_roster(node, host); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
30 if hosts[host] then |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
31 roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}}; |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
32 else |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
33 roster[support_contact] = {subscription = "from", ask = "subscribe", name = support_contact_nick, groups = {}}; |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
34 end |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
35 rostermanager.save_roster(node, host, roster); |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 node, host = jid_split(support_contact); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
986
diff
changeset
|
38 |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
39 if hosts[host] then |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
40 roster = rostermanager.load_roster(node, host); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
41 roster[jid] = {subscription = "both", groups = groups}; |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
42 rostermanager.save_roster(node, host, roster); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
43 rostermanager.roster_push(node, host, jid); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
44 else |
777
e5413b66aeec
mod_support_contact: Use module:send()
Matthew Wild <mwild1@gmail.com>
parents:
100
diff
changeset
|
45 module:send(st.presence({from=jid, to=support_contact, type="subscribe"})); |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
46 end |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 end); |