diff options
author | Clombrong <cromblong@egregore.fun> | 2025-06-17 20:40:48 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-06-17 20:40:48 +0200 |
commit | d0c1539993c64fa10ee76ebacd02ee054205630e (patch) | |
tree | be6cb15a8e06967982af7eebc7d66edb02cec760 /lib | |
parent | 824f1c0aa9cc448d054b5b8997036bc3ce78d646 (diff) |
feat(sasl): use new auth_config record for authentication
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sasl.ml | 15 |
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 |