From 690bcdb627ed8dc9e033bc8823997fcfb69ccd89 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 24 Apr 2015 09:30:52 +0200 Subject: [PATCH] fix(helper): unset stored token on refresh failure Previously we would have no way of getting rid of invalid/revoked tokens, which would render the application unusable unless the user would delete the token manually. Related to https://github.com/Byron/google-apis-rs/issues/79 --- Cargo.toml | 2 +- src/helper.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b3038af4b..d0379f76a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yup-oauth2" -version = "0.3.6" +version = "0.3.7" authors = ["Sebastian Thiel "] repository = "https://github.com/Byron/yup-oauth2" description = "A partial oauth2 implementation, providing the 'device' authorization flow" diff --git a/src/helper.rs b/src/helper.rs index dfd9ae062..8f48a314e 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -24,6 +24,7 @@ pub trait TokenStorage { type Error: 'static + Error; /// If `token` is None, it is invalid or revoked and should be removed from storage. + /// Otherwise, it should be saved. fn set(&mut self, scope_hash: u64, scopes: &Vec<&str>, token: Option) -> Option; /// A `None` result indicates that there is no token for the given scope_hash. fn get(&self, scope_hash: u64, scopes: &Vec<&str>) -> Result, Self::Error>; @@ -305,8 +306,13 @@ impl GetToken for Authenticator }, RefreshResult::RefreshError(ref err_str, ref err_description) => { self.delegate.token_refresh_failed(&err_str, &err_description); + let storage_err = + match self.storage.set(scope_key, &scopes, None) { + None => String::new(), + Some(err) => err.to_string(), + }; return Err(Box::new( - StringError::new(err_str.clone(), err_description.as_ref()))) + StringError::new(storage_err + err_str, err_description.as_ref()))) }, RefreshResult::Success(ref new_t) => { t = new_t.clone();