From 57a3151d4d550c14e0763bcf3153791d5d832dba Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 20 May 2016 18:24:28 +0200 Subject: [PATCH] fix(flows): save Token properly The installed flow didn't explicitly set the retrieved token absolute, which would cause failures down the road. --- Cargo.lock | 6 +++--- src/common.rs | 2 +- src/installed.rs | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09f851d..9b1cc9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "yup-oauth2" -version = "0.5.6" +version = "0.6.0" dependencies = [ "chrono 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -15,7 +15,7 @@ dependencies = [ "serde_macros 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", "syntex 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)", - "yup-hyper-mock 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "yup-hyper-mock 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -505,7 +505,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "yup-hyper-mock" -version = "1.3.2" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hyper 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/common.rs b/src/common.rs index 1dee61a..46c1f71 100644 --- a/src/common.rs +++ b/src/common.rs @@ -117,7 +117,7 @@ impl Token { /// Returns a DateTime object representing our expiry date. pub fn expiry_date(&self) -> DateTime { - UTC.timestamp(self.expires_in_timestamp.unwrap(), 0) + UTC.timestamp(self.expires_in_timestamp.expect("Tokens without an absolute expiry are invalid"), 0) } /// Adjust our stored expiry format to be absolute, using the current time. diff --git a/src/installed.rs b/src/installed.rs index 9c50cbd..3097ecd 100644 --- a/src/installed.rs +++ b/src/installed.rs @@ -139,14 +139,15 @@ impl InstalledFlow where C: BorrowMut // Successful response if tokens.access_token.is_some() { - let token = Token { + let mut token = Token { access_token: tokens.access_token.unwrap(), refresh_token: tokens.refresh_token.unwrap(), token_type: tokens.token_type.unwrap(), expires_in: tokens.expires_in, expires_in_timestamp: None, }; - + + token.set_expiry_absolute(); Result::Ok(token) } else { let err = io::Error::new(io::ErrorKind::Other,