From d0c1539993c64fa10ee76ebacd02ee054205630e Mon Sep 17 00:00:00 2001 From: Clombrong Date: Tue, 17 Jun 2025 20:40:48 +0200 Subject: feat(sasl): use new auth_config record for authentication --- lib/sasl.ml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/sasl.ml') 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 -- cgit v1.2.3