refactor storage get and set methods.

These previously accepted a hash and scopes. The hash was required to be
a hash of the provided scopes but that wasn't enforced by the compiler.
We now have the compiler enforce that by creating a HashedScopes type
that ties the scopes and the hash together and pass that into the
storage methods.
This commit is contained in:
Glenn Griffin
2019-11-15 09:39:07 -08:00
parent f76dea5dbd
commit 4b4b2fe3f4
3 changed files with 85 additions and 54 deletions

View File

@@ -35,8 +35,8 @@ where
where
T: AsRef<str>,
{
let scope_key = storage::ScopeHash::new(scopes);
match self.storage.get(scope_key, scopes) {
let hashed_scopes = storage::HashedScopes::from(scopes);
match self.storage.get(hashed_scopes) {
Some(t) if !t.expired() => {
// unexpired token found
Ok(t)
@@ -59,9 +59,7 @@ where
}
Ok(token) => token,
};
self.storage
.set(scope_key, scopes, Some(token.clone()))
.await;
self.storage.set(hashed_scopes, Some(token.clone())).await;
Ok(token)
}
None
@@ -74,7 +72,7 @@ where
.auth_flow
.token(&self.hyper_client, &self.app_secret, scopes)
.await?;
self.storage.set(scope_key, scopes, Some(t.clone())).await;
self.storage.set(hashed_scopes, Some(t.clone())).await;
Ok(t)
}
}