Software / code / prosody
Comparison
plugins/mod_tokenauth.lua @ 13003:34ed17ef1c1a
mod_tokenauth: Fire events on grant creation and revocation
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 28 Mar 2023 10:43:09 +0100 |
| parent | 13000:c7253174503e |
| child | 13006:d943733c6d01 |
comparison
equal
deleted
inserted
replaced
| 13002:d8e2b995f975 | 13003:34ed17ef1c1a |
|---|---|
| 52 | 52 |
| 53 local ok, err = token_store:set_key(grant_username, grant_id, grant); | 53 local ok, err = token_store:set_key(grant_username, grant_id, grant); |
| 54 if not ok then | 54 if not ok then |
| 55 return nil, err; | 55 return nil, err; |
| 56 end | 56 end |
| 57 | |
| 58 module:fire_event("token-grant-created", { | |
| 59 id = grant_id; | |
| 60 grant = grant; | |
| 61 username = grant_username; | |
| 62 host = grant_host; | |
| 63 }); | |
| 57 | 64 |
| 58 return grant; | 65 return grant; |
| 59 end | 66 end |
| 60 | 67 |
| 61 function create_token(grant_jid, grant, token_role, token_ttl, token_purpose, token_data) | 68 function create_token(grant_jid, grant, token_role, token_ttl, token_purpose, token_data) |
| 224 return nil, "invalid-token-format"; | 231 return nil, "invalid-token-format"; |
| 225 end | 232 end |
| 226 if token_host ~= module.host then | 233 if token_host ~= module.host then |
| 227 return nil, "invalid-host"; | 234 return nil, "invalid-host"; |
| 228 end | 235 end |
| 229 return token_store:set_key(token_user, token_id, nil); | 236 local ok, err = token_store:set_key(token_user, token_id, nil); |
| 237 if not ok then | |
| 238 return nil, err; | |
| 239 end | |
| 240 module:fire_event("token-grant-revoked", { id = token_id, username = token_user, host = token_host }); | |
| 241 return true; | |
| 230 end | 242 end |
| 231 | 243 |
| 232 function sasl_handler(auth_provider, purpose, extra) | 244 function sasl_handler(auth_provider, purpose, extra) |
| 233 return function (sasl, token, realm, _authzid) | 245 return function (sasl, token, realm, _authzid) |
| 234 local token_info, err = get_token_info(token); | 246 local token_info, err = get_token_info(token); |