Software /
code /
prosody
Changeset
12915:70f6a8dceb1d
mod_tokenauth: Add SASL handler backend that can accept and verify tokens
This is designed for use by other modules that want to accept tokens issued
by mod_tokenauth, without duplicating all the necessary logic.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 01 Mar 2023 13:04:36 +0000 |
parents | 12914:2b4661bd39e2 |
children | 12916:5a06d07596f9 |
files | plugins/mod_tokenauth.lua |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_tokenauth.lua Wed Mar 01 13:02:51 2023 +0000 +++ b/plugins/mod_tokenauth.lua Wed Mar 01 13:04:36 2023 +0000 @@ -122,3 +122,21 @@ end return token_store:set(token_user, token_id, nil); end + +function sasl_handler(auth_provider, purpose, extra) + return function (_, username, token, realm) + local token_info, err = get_token_info(token); + if not token_info then + module:log("debug", "SASL handler failed to verify token: %s", err); + return nil, nil, extra; + end + local token_user, token_host = jid.split(token_info.jid); + if username ~= token_user or realm ~= token_host or (purpose and token_info.purpose ~= purpose) then + return nil, nil, extra; + end + if auth_provider.is_enabled and not auth_provider.is_enabled(username) then + return true, false, token_info; + end + return true, true, token_info; + end; +end