diff --git a/README.md b/README.md index 866b7ef9..642e0a81 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ You can create a basic configuration in `$CONFIG_DIR/iamb/config.toml` that look user_id = "@user:example.com" ``` -If you homeserver is located on a different domain than the server part of the +If your homeserver is located on a different domain than the server part of the `user_id` and you don't have a [`/.well-known`][well_known_entry] entry, then you can explicitly specify the homeserver URL to use: diff --git a/config.example.toml b/config.example.toml index c4ebd653..1644b1b1 100644 --- a/config.example.toml +++ b/config.example.toml @@ -2,6 +2,7 @@ default_profile = "default" [profiles.default] user_id = "@user:matrix.org" +password_file = "/path/to/password" url = "https://matrix.org" [settings] diff --git a/src/config.rs b/src/config.rs index e7a4a47b..ff2793dc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -826,6 +826,7 @@ pub enum Layout { #[derive(Clone, Deserialize)] pub struct ProfileConfig { pub user_id: OwnedUserId, + pub password_file: Option, pub url: Option, pub settings: Option, pub dirs: Option, diff --git a/src/main.rs b/src/main.rs index 0a316c76..21b6cc56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -813,6 +813,17 @@ async fn login(worker: &Requester, settings: &ApplicationSettings) -> IambResult return Ok(()); } + if let Some(ref password_file) = settings.profile.password_file { + if let Err(e) = std::fs::read_to_string(password_file) + .map(|password| worker.login(LoginStyle::Password(password))) + { + println!("Failed to log in using password file {password_file:?}: {e}"); + println!("Continuing on to interactive login"); + } else { + return Ok(()); + } + } + loop { let login_style = match read_response("Please select login type: [p]assword / [s]ingle sign on") diff --git a/src/tests.rs b/src/tests.rs index e9b05021..dd512e70 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -216,6 +216,7 @@ pub fn mock_settings() -> ApplicationSettings { profile_name: "test".into(), profile: ProfileConfig { user_id: user_id!("@user:example.com").to_owned(), + password_file: None, url: None, settings: None, dirs: None,