Software /
code /
prosody
Comparison
plugins/mod_tokenauth.lua @ 12772:daa654dbd8de
mod_tokenauth: Allow attaching an arbitrary data table to a token
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 13 Oct 2022 22:46:19 +0100 |
parent | 12743:19113f232423 |
child | 12913:012fa81d1f5d |
comparison
equal
deleted
inserted
replaced
12771:e9fcc69ea508 | 12772:daa654dbd8de |
---|---|
11 return prosody.hosts[host].authz.get_role_by_name(role); | 11 return prosody.hosts[host].authz.get_role_by_name(role); |
12 end | 12 end |
13 return usermanager.get_user_role(username, host); | 13 return usermanager.get_user_role(username, host); |
14 end | 14 end |
15 | 15 |
16 function create_jid_token(actor_jid, token_jid, token_role, token_ttl) | 16 function create_jid_token(actor_jid, token_jid, token_role, token_ttl, token_data) |
17 token_jid = jid.prep(token_jid); | 17 token_jid = jid.prep(token_jid); |
18 if not actor_jid or token_jid ~= actor_jid and not jid.compare(token_jid, actor_jid) then | 18 if not actor_jid or token_jid ~= actor_jid and not jid.compare(token_jid, actor_jid) then |
19 return nil, "not-authorized"; | 19 return nil, "not-authorized"; |
20 end | 20 end |
21 | 21 |
31 expires = token_ttl and (os.time() + token_ttl) or nil; | 31 expires = token_ttl and (os.time() + token_ttl) or nil; |
32 jid = token_jid; | 32 jid = token_jid; |
33 | 33 |
34 resource = token_resource; | 34 resource = token_resource; |
35 role = token_role; | 35 role = token_role; |
36 data = token_data; | |
36 }; | 37 }; |
37 | 38 |
38 local token_id = id.long(); | 39 local token_id = id.long(); |
39 local token = base64.encode("1;"..jid.join(token_username, token_host)..";"..token_id); | 40 local token = base64.encode("1;"..jid.join(token_username, token_host)..";"..token_id); |
40 token_store:set(token_username, token_id, token_info); | 41 token_store:set(token_username, token_id, token_info); |