mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-19 21:29:52 -07:00
Add support for logging in with SSO (#160)
This commit is contained in:
parent
8943909f06
commit
25eef55eb7
5 changed files with 129 additions and 4 deletions
|
@ -421,6 +421,7 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) {
|
|||
pub enum LoginStyle {
|
||||
SessionRestore(Session),
|
||||
Password(String),
|
||||
SingleSignOn,
|
||||
}
|
||||
|
||||
pub struct ClientResponse<T>(Receiver<T>);
|
||||
|
@ -1071,6 +1072,29 @@ impl ClientWorker {
|
|||
let session = Session::from(resp);
|
||||
serde_json::to_writer(writer, &session).map_err(IambError::from)?;
|
||||
},
|
||||
LoginStyle::SingleSignOn => {
|
||||
let resp = client
|
||||
.login_sso(|url| {
|
||||
let opened = format!(
|
||||
"The following URL should have been opened in your browser:\n {url}"
|
||||
);
|
||||
|
||||
async move {
|
||||
tokio::task::spawn_blocking(move || open::that(url));
|
||||
println!("\n{opened}\n");
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
.initial_device_display_name(initial_devname().as_str())
|
||||
.send()
|
||||
.await
|
||||
.map_err(IambError::from)?;
|
||||
|
||||
let file = File::create(self.settings.session_json.as_path())?;
|
||||
let writer = BufWriter::new(file);
|
||||
let session = Session::from(resp);
|
||||
serde_json::to_writer(writer, &session).map_err(IambError::from)?;
|
||||
},
|
||||
}
|
||||
|
||||
self.sync_handle = tokio::spawn(async move {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue