Skip to content

Commit

Permalink
fix(helper): unset stored token on refresh failure
Browse files Browse the repository at this point in the history
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 Byron/google-apis-rs#79
  • Loading branch information
Byron committed Apr 24, 2015
1 parent 1ce4147 commit 690bcdb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "yup-oauth2"
version = "0.3.6"
version = "0.3.7"
authors = ["Sebastian Thiel <[email protected]>"]
repository = "https://github.com/Byron/yup-oauth2"
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
Expand Down
8 changes: 7 additions & 1 deletion src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token>) -> Option<Self::Error>;
/// A `None` result indicates that there is no token for the given scope_hash.
fn get(&self, scope_hash: u64, scopes: &Vec<&str>) -> Result<Option<Token>, Self::Error>;
Expand Down Expand Up @@ -305,8 +306,13 @@ impl<D, S, C> GetToken for Authenticator<D, S, C>
},
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();
Expand Down

0 comments on commit 690bcdb

Please sign in to comment.