fix(sdk): Ensure that our login_with_sso() Client method is Send

This commit is contained in:
Damir Jelić
2022-03-07 14:43:42 +01:00

View File

@@ -925,9 +925,10 @@ impl Client {
/// [`login_with_token`]: #method.login_with_token
/// [`restore_login`]: #method.restore_login
#[cfg(all(feature = "sso_login", not(target_arch = "wasm32")))]
#[deny(clippy::future_not_send)]
pub async fn login_with_sso<C>(
&self,
use_sso_login_url: impl Fn(String) -> C,
use_sso_login_url: impl FnOnce(String) -> C + Send,
server_url: Option<&str>,
server_response: Option<&str>,
device_id: Option<&str>,
@@ -935,7 +936,7 @@ impl Client {
idp_id: Option<&str>,
) -> Result<login::v3::Response>
where
C: Future<Output = Result<()>>,
C: Future<Output = Result<()>> + Send,
{
use std::{
collections::HashMap,
@@ -951,7 +952,9 @@ impl Client {
/// The number of times the SSO server will try to bind to a random port
const SSO_SERVER_BIND_TRIES: u8 = 10;
info!("Logging in to {}", self.homeserver().await);
let homeserver = self.homeserver().await;
info!("Logging in to {}", homeserver);
let (signal_tx, signal_rx) = tokio::sync::oneshot::channel();
let (data_tx, data_rx) = tokio::sync::oneshot::channel();
let data_tx_mutex = Arc::new(std::sync::Mutex::new(Some(data_tx)));
@@ -992,10 +995,9 @@ impl Client {
let mut n = 0u8;
let mut port = 0u16;
let mut res = Err(IoError::new(IoErrorKind::Other, ""));
let mut rng = thread_rng();
while res.is_err() && n < SSO_SERVER_BIND_TRIES {
port = rng.gen_range(SSO_SERVER_BIND_RANGE);
port = thread_rng().gen_range(SSO_SERVER_BIND_RANGE);
res = tokio::net::TcpListener::bind((host, port)).await;
n += 1;
}
@@ -1102,13 +1104,15 @@ impl Client {
/// [`get_sso_login_url`]: #method.get_sso_login_url
/// [`restore_login`]: #method.restore_login
#[instrument(skip(token))]
#[deny(clippy::future_not_send)]
pub async fn login_with_token(
&self,
token: &str,
device_id: Option<&str>,
initial_device_display_name: Option<&str>,
) -> Result<login::v3::Response> {
info!("Logging in to {}", self.homeserver().await);
let homeserver = self.homeserver().await;
info!("Logging in to {}", homeserver);
let request = assign!(
login::v3::Request::new(