Commit 25eef55eb7
25eef55eb747fdf161918d8f2d357cca8749c9cc
parent: 8943909f06
Unregistered key
chloe <email@clh.sh> · 2023-11-04 21:39 UTC
committer: <noreply@github.com>
Add support for logging in with SSO (#160)
Layout: unified · split
Cargo.lock
+86
| @@ -1418,6 +1418,31 @@ version = "0.14.1" |
| 1418 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1418 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1419 | checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" |
1419 | checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" |
| 1420 | |
1420 | |
| |
1421 | [[package]] |
| |
1422 | name = "headers" |
| |
1423 | version = "0.3.8" |
| |
1424 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| |
1425 | checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" |
| |
1426 | dependencies = [ |
| |
1427 | "base64 0.13.1", |
| |
1428 | "bitflags 1.3.2", |
| |
1429 | "bytes", |
| |
1430 | "headers-core", |
| |
1431 | "http", |
| |
1432 | "httpdate", |
| |
1433 | "mime", |
| |
1434 | "sha1", |
| |
1435 | ] |
| |
1436 | |
| |
1437 | [[package]] |
| |
1438 | name = "headers-core" |
| |
1439 | version = "0.2.0" |
| |
1440 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| |
1441 | checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" |
| |
1442 | dependencies = [ |
| |
1443 | "http", |
| |
1444 | ] |
| |
1445 | |
| 1421 | [[package]] |
1446 | [[package]] |
| 1422 | name = "heck" |
1447 | name = "heck" |
| 1423 | version = "0.4.1" |
1448 | version = "0.4.1" |
| @@ -1960,14 +1985,17 @@ dependencies = [ |
| 1960 | "matrix-sdk-indexeddb", |
1985 | "matrix-sdk-indexeddb", |
| 1961 | "matrix-sdk-sled", |
1986 | "matrix-sdk-sled", |
| 1962 | "mime", |
1987 | "mime", |
| |
1988 | "rand 0.8.5", |
| 1963 | "reqwest", |
1989 | "reqwest", |
| 1964 | "ruma", |
1990 | "ruma", |
| 1965 | "serde", |
1991 | "serde", |
| 1966 | "serde_json", |
1992 | "serde_json", |
| 1967 | "thiserror", |
1993 | "thiserror", |
| 1968 | "tokio", |
1994 | "tokio", |
| |
1995 | "tokio-stream", |
| 1969 | "tracing", |
1996 | "tracing", |
| 1970 | "url", |
1997 | "url", |
| |
1998 | "warp", |
| 1971 | "wasm-timer", |
1999 | "wasm-timer", |
| 1972 | "zeroize", |
2000 | "zeroize", |
| 1973 | ] |
2001 | ] |
| @@ -3186,6 +3214,12 @@ dependencies = [ |
| 3186 | "winapi-util", |
3214 | "winapi-util", |
| 3187 | ] |
3215 | ] |
| 3188 | |
3216 | |
| |
3217 | [[package]] |
| |
3218 | name = "scoped-tls" |
| |
3219 | version = "1.0.1" |
| |
3220 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| |
3221 | checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" |
| |
3222 | |
| 3189 | [[package]] |
3223 | [[package]] |
| 3190 | name = "scopeguard" |
3224 | name = "scopeguard" |
| 3191 | version = "1.2.0" |
3225 | version = "1.2.0" |
| @@ -3260,6 +3294,17 @@ dependencies = [ |
| 3260 | "serde", |
3294 | "serde", |
| 3261 | ] |
3295 | ] |
| 3262 | |
3296 | |
| |
3297 | [[package]] |
| |
3298 | name = "sha1" |
| |
3299 | version = "0.10.5" |
| |
3300 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| |
3301 | checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" |
| |
3302 | dependencies = [ |
| |
3303 | "cfg-if", |
| |
3304 | "cpufeatures", |
| |
3305 | "digest 0.10.7", |
| |
3306 | ] |
| |
3307 | |
| 3263 | [[package]] |
3308 | [[package]] |
| 3264 | name = "sha2" |
3309 | name = "sha2" |
| 3265 | version = "0.9.9" |
3310 | version = "0.9.9" |
| @@ -3743,6 +3788,17 @@ dependencies = [ |
| 3743 | "tokio", |
3788 | "tokio", |
| 3744 | ] |
3789 | ] |
| 3745 | |
3790 | |
| |
3791 | [[package]] |
| |
3792 | name = "tokio-stream" |
| |
3793 | version = "0.1.14" |
| |
3794 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| |
3795 | checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" |
| |
3796 | dependencies = [ |
| |
3797 | "futures-core", |
| |
3798 | "pin-project-lite", |
| |
3799 | "tokio", |
| |
3800 | ] |
| |
3801 | |
| 3746 | [[package]] |
3802 | [[package]] |
| 3747 | name = "tokio-util" |
3803 | name = "tokio-util" |
| 3748 | version = "0.7.9" |
3804 | version = "0.7.9" |
| @@ -3796,6 +3852,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3796 | checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" |
3852 | checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" |
| 3797 | dependencies = [ |
3853 | dependencies = [ |
| 3798 | "cfg-if", |
3854 | "cfg-if", |
| |
3855 | "log", |
| 3799 | "pin-project-lite", |
3856 | "pin-project-lite", |
| 3800 | "tracing-attributes", |
3857 | "tracing-attributes", |
| 3801 | "tracing-core", |
3858 | "tracing-core", |
| @@ -4056,6 +4113,35 @@ dependencies = [ |
| 4056 | "try-lock", |
4113 | "try-lock", |
| 4057 | ] |
4114 | ] |
| 4058 | |
4115 | |
| |
4116 | [[package]] |
| |
4117 | name = "warp" |
| |
4118 | version = "0.3.5" |
| |
4119 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| |
4120 | checksum = "ba431ef570df1287f7f8b07e376491ad54f84d26ac473489427231e1718e1f69" |
| |
4121 | dependencies = [ |
| |
4122 | "bytes", |
| |
4123 | "futures-channel", |
| |
4124 | "futures-util", |
| |
4125 | "headers", |
| |
4126 | "http", |
| |
4127 | "hyper", |
| |
4128 | "log", |
| |
4129 | "mime", |
| |
4130 | "mime_guess", |
| |
4131 | "percent-encoding", |
| |
4132 | "pin-project", |
| |
4133 | "rustls-pemfile", |
| |
4134 | "scoped-tls", |
| |
4135 | "serde", |
| |
4136 | "serde_json", |
| |
4137 | "serde_urlencoded", |
| |
4138 | "tokio", |
| |
4139 | "tokio-stream", |
| |
4140 | "tokio-util", |
| |
4141 | "tower-service", |
| |
4142 | "tracing", |
| |
4143 | ] |
| |
4144 | |
| 4059 | [[package]] |
4145 | [[package]] |
| 4060 | name = "wasi" |
4146 | name = "wasi" |
| 4061 | version = "0.9.0+wasi-snapshot-preview1" |
4147 | version = "0.9.0+wasi-snapshot-preview1" |
Cargo.toml
+1 −1
| @@ -61,7 +61,7 @@ rev = "f9f0517ed6a6152c1eab36d2e71b11f38831d5e6" |
| 61 | [dependencies.matrix-sdk] |
61 | [dependencies.matrix-sdk] |
| 62 | version = "^0.6.2" |
62 | version = "^0.6.2" |
| 63 | default-features = false |
63 | default-features = false |
| 64 | features = ["e2e-encryption", "sled", "rustls-tls"] |
64 | features = ["e2e-encryption", "sled", "rustls-tls", "sso-login"] |
| 65 | |
65 | |
| 66 | [dependencies.tokio] |
66 | [dependencies.tokio] |
| 67 | version = "1.24.1" |
67 | version = "1.24.1" |
README.md
+1 −1
| @@ -103,7 +103,7 @@ two other TUI clients and Element Web: |
| 103 | | Message editing | ✔️ | ✔️ | ❌ | ✔️ | |
103 | | Message editing | ✔️ | ✔️ | ❌ | ✔️ | |
| 104 | | Room upgrades | ❌ ([#41]) | ✔️ | ❌ | ✔️ | |
104 | | Room upgrades | ❌ ([#41]) | ✔️ | ❌ | ✔️ | |
| 105 | | Localisations | ❌ | 1 | ❌ | 44 | |
105 | | Localisations | ❌ | 1 | ❌ | 44 | |
| 106 | | SSO Support | ❌ | ✔️ | ✔️ | ✔️ | |
106 | | SSO Support | ✔️ | ✔️ | ✔️ | ✔️ | |
| 107 | |
107 | |
| 108 | ## License |
108 | ## License |
| 109 | |
109 | |
src/main.rs
+17 −2
| @@ -679,9 +679,24 @@ async fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult< |
| 679 | } |
679 | } |
| 680 | |
680 | |
| 681 | loop { |
681 | loop { |
| 682 | let password = rpassword::prompt_password("Password: ")?; |
682 | println!("Please select login type: [p]assword / [s]ingle sign on"); |
| 683 | |
683 | |
| 684 | match worker.login(LoginStyle::Password(password)) { |
684 | let mut input = String::new(); |
| |
685 | std::io::stdin().read_line(&mut input).unwrap(); |
| |
686 | |
| |
687 | let login_style = match input.chars().next().map(|c| c.to_ascii_lowercase()) { |
| |
688 | None | Some('p') => { |
| |
689 | let password = rpassword::prompt_password("Password: ")?; |
| |
690 | LoginStyle::Password(password) |
| |
691 | }, |
| |
692 | Some('s') => LoginStyle::SingleSignOn, |
| |
693 | Some(_) => { |
| |
694 | println!("Failed to login. Please enter 'p' or 's'"); |
| |
695 | continue; |
| |
696 | }, |
| |
697 | }; |
| |
698 | |
| |
699 | match worker.login(login_style) { |
| 685 | Ok(info) => { |
700 | Ok(info) => { |
| 686 | if let Some(msg) = info { |
701 | if let Some(msg) = info { |
| 687 | println!("{msg}"); |
702 | println!("{msg}"); |
src/worker.rs
+24
| @@ -421,6 +421,7 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) { |
| 421 | pub enum LoginStyle { |
421 | pub enum LoginStyle { |
| 422 | SessionRestore(Session), |
422 | SessionRestore(Session), |
| 423 | Password(String), |
423 | Password(String), |
| |
424 | SingleSignOn, |
| 424 | } |
425 | } |
| 425 | |
426 | |
| 426 | pub struct ClientResponse<T>(Receiver<T>); |
427 | pub struct ClientResponse<T>(Receiver<T>); |
| @@ -1071,6 +1072,29 @@ impl ClientWorker { |
| 1071 | let session = Session::from(resp); |
1072 | let session = Session::from(resp); |
| 1072 | serde_json::to_writer(writer, &session).map_err(IambError::from)?; |
1073 | serde_json::to_writer(writer, &session).map_err(IambError::from)?; |
| 1073 | }, |
1074 | }, |
| |
1075 | LoginStyle::SingleSignOn => { |
| |
1076 | let resp = client |
| |
1077 | .login_sso(|url| { |
| |
1078 | let opened = format!( |
| |
1079 | "The following URL should have been opened in your browser:\n {url}" |
| |
1080 | ); |
| |
1081 | |
| |
1082 | async move { |
| |
1083 | tokio::task::spawn_blocking(move || open::that(url)); |
| |
1084 | println!("\n{opened}\n"); |
| |
1085 | Ok(()) |
| |
1086 | } |
| |
1087 | }) |
| |
1088 | .initial_device_display_name(initial_devname().as_str()) |
| |
1089 | .send() |
| |
1090 | .await |
| |
1091 | .map_err(IambError::from)?; |
| |
1092 | |
| |
1093 | let file = File::create(self.settings.session_json.as_path())?; |
| |
1094 | let writer = BufWriter::new(file); |
| |
1095 | let session = Session::from(resp); |
| |
1096 | serde_json::to_writer(writer, &session).map_err(IambError::from)?; |
| |
1097 | }, |
| 1074 | } |
1098 | } |
| 1075 | |
1099 | |
| 1076 | self.sync_handle = tokio::spawn(async move { |
1100 | self.sync_handle = tokio::spawn(async move { |