diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-10-17 03:14:03 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-10-17 03:14:03 -0400 |
commit | 0a1685fc6e8b87865c32e2baaded01ae70368a4b (patch) | |
tree | e0a4bf5986a65cc2016d358c18e0cfbdb616cb4c | |
parent | f4e6745c78c016b6103bc595ff99514b5adf973b (diff) | |
download | teleterm-0a1685fc6e8b87865c32e2baaded01ae70368a4b.tar.gz teleterm-0a1685fc6e8b87865c32e2baaded01ae70368a4b.zip |
also factor out client auth id saving
-rw-r--r-- | src/client.rs | 11 | ||||
-rw-r--r-- | 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<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> ).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<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> )) }) .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<dyn futures::future::Future<Item = String, Error = Error> + Send>; } +pub fn save_client_auth_id( + auth: crate::protocol::AuthType, + id: &str, +) -> impl futures::future::Future<Item = (), Error = Error> { + 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<String> { |