aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd/stream.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-16 03:48:58 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-16 03:48:58 -0400
commitc4ea88441cd5f67683008da99949e5101183b8b1 (patch)
tree0b8d25047e85c96f05597dc0008dbd794dfc12ec /src/cmd/stream.rs
parentf1cb4b1ea5dc268077d8d7be1c335208105ddcc5 (diff)
downloadteleterm-c4ea88441cd5f67683008da99949e5101183b8b1.tar.gz
teleterm-c4ea88441cd5f67683008da99949e5101183b8b1.zip
cache refresh tokens and use them when the exist
to avoid needing to go through the browser auth flow every time
Diffstat (limited to 'src/cmd/stream.rs')
-rw-r--r--src/cmd/stream.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/cmd/stream.rs b/src/cmd/stream.rs
index 66ed68b..c1e1efa 100644
--- a/src/cmd/stream.rs
+++ b/src/cmd/stream.rs
@@ -1,4 +1,5 @@
use crate::prelude::*;
+use std::io::Read as _;
use tokio::io::AsyncWrite as _;
pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
@@ -30,7 +31,16 @@ pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
pub fn run<'a>(matches: &clap::ArgMatches<'a>) -> super::Result<()> {
let auth = if matches.is_present("login-recurse-center") {
- crate::protocol::Auth::RecurseCenter { id: None }
+ let auth = crate::protocol::Auth::RecurseCenter { id: None };
+ let id_file = crate::dirs::Dirs::new()
+ .data_file(&format!("client-oauth-{}", auth.name()));
+ let id = std::fs::File::open(id_file).ok().and_then(|mut file| {
+ let mut id = vec![];
+ file.read_to_end(&mut id).ok().map(|_| {
+ std::string::String::from_utf8_lossy(&id).to_string()
+ })
+ });
+ crate::protocol::Auth::RecurseCenter { id }
} else {
let username = matches
.value_of("login-plain")