summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-17 20:40:48 +0200
committerClombrong <cromblong@egregore.fun>2025-06-17 20:40:48 +0200
commitd0c1539993c64fa10ee76ebacd02ee054205630e (patch)
treebe6cb15a8e06967982af7eebc7d66edb02cec760 /lib
parent824f1c0aa9cc448d054b5b8997036bc3ce78d646 (diff)
feat(sasl): use new auth_config record for authentication
Diffstat (limited to 'lib')
-rw-r--r--lib/sasl.ml15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/sasl.ml b/lib/sasl.ml
index 5a0dd80..3c2ae20 100644
--- a/lib/sasl.ml
+++ b/lib/sasl.ml
@@ -2,6 +2,12 @@ open Lwt.Syntax
type auth_mechanism = PLAIN [@@deriving show { with_path = false }]
+type auth_config = {
+ jid : string;
+ password : string;
+ preferred_mechanisms : auth_mechanism list;
+}
+
type sasl_error =
| NotAuthorized
| MalformedRequest
@@ -47,3 +53,12 @@ let send_auth_stanza (stream, push) localpart pass mechanism =
| Some stanza -> parse_sasl_response stanza |> Lwt.return
| None -> Lwt.fail Stream.ClosedStream
with exn -> Lwt.fail exn
+
+let authenticate (portal : Portal.t) (config : auth_config) =
+ let {jid; password; _} = config
+ (* Probably not exactly compliant with https://xmpp.org/extensions/xep-0029.html,
+ but it's just for simplicity's sake in alpha. *)
+ in let localpart = match String.split_on_char '@' jid with
+ | [localpart; _domain] -> localpart
+ | _ -> failwith "Invalid JID"
+ in send_auth_stanza portal localpart password PLAIN