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,
|
Ok(token) => token,
|
||||||
};
|
};
|
||||||
self.storage.set(hashed_scopes, Some(token.clone())).await;
|
self.storage.set(hashed_scopes, token.clone()).await;
|
||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
@@ -72,7 +72,7 @@ where
|
|||||||
.auth_flow
|
.auth_flow
|
||||||
.token(&self.hyper_client, &self.app_secret, scopes)
|
.token(&self.hyper_client, &self.app_secret, scopes)
|
||||||
.await?;
|
.await?;
|
||||||
self.storage.set(hashed_scopes, Some(t.clone())).await;
|
self.storage.set(hashed_scopes, t.clone()).await;
|
||||||
Ok(t)
|
Ok(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ where
|
|||||||
scopes,
|
scopes,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
cache.set(hashed_scopes, Some(token.clone())).await;
|
cache.set(hashed_scopes, token.clone()).await;
|
||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
/// Send a request for a new Bearer token to the OAuth provider.
|
/// Send a request for a new Bearer token to the OAuth provider.
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ pub(crate) enum Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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
|
where
|
||||||
T: AsRef<str>,
|
T: AsRef<str>,
|
||||||
{
|
{
|
||||||
@@ -156,29 +156,24 @@ impl JSONTokens {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set<T>(&mut self, scopes: HashedScopes<T>, token: Option<Token>)
|
fn set<T>(&mut self, scopes: HashedScopes<T>, token: Token)
|
||||||
where
|
where
|
||||||
T: AsRef<str>,
|
T: AsRef<str>,
|
||||||
{
|
{
|
||||||
eprintln!("setting: {:?}, {:?}", scopes.hash, token);
|
eprintln!("setting: {:?}, {:?}", scopes.hash, token);
|
||||||
self.tokens.retain(|x| x.hash != scopes.hash);
|
self.tokens.retain(|x| x.hash != scopes.hash);
|
||||||
|
|
||||||
match token {
|
self.tokens.push(JSONToken {
|
||||||
None => (),
|
hash: scopes.hash,
|
||||||
Some(t) => {
|
scopes: Some(
|
||||||
self.tokens.push(JSONToken {
|
scopes
|
||||||
hash: scopes.hash,
|
.scopes
|
||||||
scopes: Some(
|
.iter()
|
||||||
scopes
|
.map(|x| x.as_ref().to_string())
|
||||||
.scopes
|
.collect(),
|
||||||
.iter()
|
),
|
||||||
.map(|x| x.as_ref().to_string())
|
token,
|
||||||
.collect(),
|
});
|
||||||
),
|
|
||||||
token: t,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ideally this function would accept &Path, but tokio requires the
|
// 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
|
where
|
||||||
T: AsRef<str>,
|
T: AsRef<str>,
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user