2023-12-30 22:08:37 -05:00
|
|
|
use sasl::common::Credentials;
|
2023-12-30 00:07:59 -05:00
|
|
|
use xmpp_parsers::{ns, Jid};
|
|
|
|
|
|
2023-12-30 22:08:37 -05:00
|
|
|
use crate::client::auth::auth;
|
|
|
|
|
use crate::client::bind::bind;
|
|
|
|
|
use crate::connect::ServerConnector;
|
2023-12-30 00:07:59 -05:00
|
|
|
use crate::{xmpp_stream::XMPPStream, Error};
|
|
|
|
|
|
|
|
|
|
/// Log into an XMPP server as a client with a jid+pass
|
|
|
|
|
/// does channel binding if supported
|
|
|
|
|
pub async fn client_login<C: ServerConnector>(
|
|
|
|
|
server: C,
|
|
|
|
|
jid: Jid,
|
|
|
|
|
password: String,
|
|
|
|
|
) -> Result<XMPPStream<C::Stream>, Error> {
|
2024-03-03 16:15:04 +01:00
|
|
|
let username = jid.node().unwrap().as_str();
|
2023-12-30 00:07:59 -05:00
|
|
|
let password = password;
|
|
|
|
|
|
2023-12-30 22:08:37 -05:00
|
|
|
let xmpp_stream = server.connect(&jid, ns::JABBER_CLIENT).await?;
|
2023-12-30 00:07:59 -05:00
|
|
|
|
|
|
|
|
let channel_binding = C::channel_binding(xmpp_stream.stream.get_ref())?;
|
|
|
|
|
|
|
|
|
|
let creds = Credentials::default()
|
|
|
|
|
.with_username(username)
|
|
|
|
|
.with_password(password)
|
|
|
|
|
.with_channel_binding(channel_binding);
|
|
|
|
|
// Authenticated (unspecified) stream
|
|
|
|
|
let stream = auth(xmpp_stream, creds).await?;
|
|
|
|
|
// Authenticated XMPPStream
|
|
|
|
|
let xmpp_stream = XMPPStream::start(stream, jid, ns::JABBER_CLIENT.to_owned()).await?;
|
|
|
|
|
|
|
|
|
|
// XMPPStream bound to user session
|
|
|
|
|
let xmpp_stream = bind(xmpp_stream).await?;
|
|
|
|
|
Ok(xmpp_stream)
|
|
|
|
|
}
|