From 0a1685fc6e8b87865c32e2baaded01ae70368a4b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 17 Oct 2019 03:14:03 -0400 Subject: also factor out client auth id saving --- src/client.rs | 11 ++--------- src/oauth.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/client.rs b/src/client.rs index 59ed96d..d4e925b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -337,7 +337,7 @@ impl ).unwrap(); } - let auth_name = self.auth.name().to_string(); + let auth_type = self.auth.auth_type(); let id = id.to_string(); let addr = OAUTH_LISTEN_ADDRESS .parse() @@ -394,14 +394,7 @@ impl )) }) .and_then(move |(msg, sock)| { - let id_file = crate::dirs::Dirs::new() - .data_file(&format!("client-oauth-{}", auth_name)); - tokio::fs::File::create(id_file) - .context(crate::error::CreateFile) - .and_then(|file| { - tokio::io::write_all(file, id) - .context(crate::error::WriteFile) - }) + crate::oauth::save_client_auth_id(auth_type, &id) .map(|_| (msg, sock)) }) .and_then(|(msg, sock)| { diff --git a/src/oauth.rs b/src/oauth.rs index bf9c4bc..6264ce2 100644 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -73,6 +73,20 @@ pub trait Oauth { ) -> Box + Send>; } +pub fn save_client_auth_id( + auth: crate::protocol::AuthType, + id: &str, +) -> impl futures::future::Future { + let id_file = client_id_file(auth); + let id = id.to_string(); + tokio::fs::File::create(id_file) + .context(crate::error::CreateFile) + .and_then(|file| { + tokio::io::write_all(file, id).context(crate::error::WriteFile) + }) + .map(|_| ()) +} + pub fn load_client_auth_id( auth: crate::protocol::AuthType, ) -> Option { -- cgit v1.2.3-54-g00ecf