From 1d9e8a491cea557b3ac11b35e57f4b2718144d4a Mon Sep 17 00:00:00 2001 From: Andre Fatton Date: Tue, 14 Jan 2025 14:11:03 +0100 Subject: [PATCH] Add optional callback versions to auth_on_register hooks --- src/auth_on_register_hook.erl | 12 ++++++++++++ src/auth_on_register_m5_hook.erl | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/auth_on_register_hook.erl b/src/auth_on_register_hook.erl index f1e5992..8770500 100644 --- a/src/auth_on_register_hook.erl +++ b/src/auth_on_register_hook.erl @@ -11,6 +11,18 @@ | {ok, [reg_modifiers()]} | {error, invalid_credentials | any()} | next. +%% optional callback including Opts map, for easier future extensions +-callback auth_on_register(Peer :: peer(), + SubscriberId :: subscriber_id(), + UserName :: username(), + Password :: password(), + CleanSession :: flag(), + Opts :: map()) -> ok + | {ok, [reg_modifiers()]} + | {error, invalid_credentials | any()} + | next. +-optional_callbacks([auth_on_register/6]). + -type reg_modifiers() :: %% Change the mountpoint for the session. {mountpoint, mountpoint()} diff --git a/src/auth_on_register_m5_hook.erl b/src/auth_on_register_m5_hook.erl index edd5bae..cfb9971 100644 --- a/src/auth_on_register_m5_hook.erl +++ b/src/auth_on_register_m5_hook.erl @@ -16,6 +16,22 @@ {error, atom()} | %% will be turned into ?NOT_AUTHORIZED next. +%% optional callback including Opts map, for easier future extensions +-callback auth_on_register_m5(Peer :: peer(), + SubscriberId :: subscriber_id(), + UserName :: username(), + Password :: password(), + CleanStart :: flag(), + Properties :: reg_properties(), + Opts :: map()) -> + ok | + {ok, reg_modifiers()} | + {error, #{reason_code => err_reason_code_name()}} | + {error, atom()} | %% will be turned into ?NOT_AUTHORIZED + next. + +-optional_callbacks([auth_on_register_m5/7]). + -type reg_properties() :: #{ p_session_expiry_interval => seconds(),