mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-01 00:50:04 +01:00
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
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
|
||||
name = "yup-oauth2"
|
||||
version = "0.3.6"
|
||||
version = "0.3.7"
|
||||
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
|
||||
repository = "https://github.com/Byron/yup-oauth2"
|
||||
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
|
||||
|
||||
@@ -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>;
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user