aboutsummaryrefslogtreecommitdiff
path: root/lib/sasl.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sasl.ml')
-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