mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-02-23 15:50:00 +01:00
storage set method should just accept a Token rather than Option<Token>.
No caller ever provided a None value. Presumably a None value should delete the token, but it didn't do that and that would be more clearly done with a remove or delete method.
This commit is contained in:
@@ -59,7 +59,7 @@ where
|
||||
}
|
||||
Ok(token) => token,
|
||||
};
|
||||
self.storage.set(hashed_scopes, Some(token.clone())).await;
|
||||
self.storage.set(hashed_scopes, token.clone()).await;
|
||||
Ok(token)
|
||||
}
|
||||
None
|
||||
@@ -72,7 +72,7 @@ where
|
||||
.auth_flow
|
||||
.token(&self.hyper_client, &self.app_secret, scopes)
|
||||
.await?;
|
||||
self.storage.set(hashed_scopes, Some(t.clone())).await;
|
||||
self.storage.set(hashed_scopes, t.clone()).await;
|
||||
Ok(t)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ where
|
||||
scopes,
|
||||
)
|
||||
.await?;
|
||||
cache.set(hashed_scopes, Some(token.clone())).await;
|
||||
cache.set(hashed_scopes, token.clone()).await;
|
||||
Ok(token)
|
||||
}
|
||||
/// Send a request for a new Bearer token to the OAuth provider.
|
||||
|
||||
@@ -69,7 +69,7 @@ pub(crate) enum Storage {
|
||||
}
|
||||
|
||||
impl Storage {
|
||||
pub(crate) async fn set<T>(&self, scopes: HashedScopes<'_, T>, token: Option<Token>)
|
||||
pub(crate) async fn set<T>(&self, scopes: HashedScopes<'_, T>, token: Token)
|
||||
where
|
||||
T: AsRef<str>,
|
||||
{
|
||||
@@ -156,29 +156,24 @@ impl JSONTokens {
|
||||
None
|
||||
}
|
||||
|
||||
fn set<T>(&mut self, scopes: HashedScopes<T>, token: Option<Token>)
|
||||
fn set<T>(&mut self, scopes: HashedScopes<T>, token: Token)
|
||||
where
|
||||
T: AsRef<str>,
|
||||
{
|
||||
eprintln!("setting: {:?}, {:?}", scopes.hash, token);
|
||||
self.tokens.retain(|x| x.hash != scopes.hash);
|
||||
|
||||
match token {
|
||||
None => (),
|
||||
Some(t) => {
|
||||
self.tokens.push(JSONToken {
|
||||
hash: scopes.hash,
|
||||
scopes: Some(
|
||||
scopes
|
||||
.scopes
|
||||
.iter()
|
||||
.map(|x| x.as_ref().to_string())
|
||||
.collect(),
|
||||
),
|
||||
token: t,
|
||||
});
|
||||
}
|
||||
}
|
||||
self.tokens.push(JSONToken {
|
||||
hash: scopes.hash,
|
||||
scopes: Some(
|
||||
scopes
|
||||
.scopes
|
||||
.iter()
|
||||
.map(|x| x.as_ref().to_string())
|
||||
.collect(),
|
||||
),
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: ideally this function would accept &Path, but tokio requires the
|
||||
@@ -219,7 +214,7 @@ impl DiskStorage {
|
||||
})
|
||||
}
|
||||
|
||||
async fn set<T>(&self, scopes: HashedScopes<'_, T>, token: Option<Token>)
|
||||
async fn set<T>(&self, scopes: HashedScopes<'_, T>, token: Token)
|
||||
where
|
||||
T: AsRef<str>,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user