mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-22 18:15:28 +01:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user