mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-02-23 15:50:00 +01:00
Revert mutable authenticator interface change
Instead, suggest using interior mutability (and RwLock in the example) to manage storage of token states. This makes it easier to share authenticators between threads.
This commit is contained in:
@@ -47,7 +47,7 @@ where
|
||||
C: hyper::client::connect::Connect + Clone + Send + Sync + 'static,
|
||||
{
|
||||
/// Return the current token for the provided scopes.
|
||||
pub async fn token<'a, T>(&'a mut self, scopes: &'a [T]) -> Result<AccessToken, Error>
|
||||
pub async fn token<'a, T>(&'a self, scopes: &'a [T]) -> Result<AccessToken, Error>
|
||||
where
|
||||
T: AsRef<str>,
|
||||
{
|
||||
@@ -57,7 +57,7 @@ where
|
||||
/// Return a token for the provided scopes, but don't reuse cached tokens. Instead,
|
||||
/// always fetch a new token from the OAuth server.
|
||||
pub async fn force_refreshed_token<'a, T>(
|
||||
&'a mut self,
|
||||
&'a self,
|
||||
scopes: &'a [T],
|
||||
) -> Result<AccessToken, Error>
|
||||
where
|
||||
@@ -68,7 +68,7 @@ where
|
||||
|
||||
/// Return a cached token or fetch a new one from the server.
|
||||
async fn find_token<'a, T>(
|
||||
&'a mut self,
|
||||
&'a self,
|
||||
scopes: &'a [T],
|
||||
force_refresh: bool,
|
||||
) -> Result<AccessToken, Error>
|
||||
|
||||
@@ -137,7 +137,7 @@ pub trait TokenStorage: Send + Sync {
|
||||
/// Store a token for the given set of scopes so that it can be retrieved later by get()
|
||||
/// ScopeSet implements Hash so that you can easily serialize and store it.
|
||||
/// TokenInfo can be serialized with serde.
|
||||
async fn set(&mut self, scopes: ScopeSet<'_, &str>, token: TokenInfo) -> anyhow::Result<()>;
|
||||
async fn set(&self, scopes: ScopeSet<'_, &str>, token: TokenInfo) -> anyhow::Result<()>;
|
||||
|
||||
/// Retrieve a token stored by set for the given set of scopes
|
||||
async fn get(&self, scopes: ScopeSet<'_, &str>) -> Option<TokenInfo>;
|
||||
@@ -151,7 +151,7 @@ pub(crate) enum Storage {
|
||||
|
||||
impl Storage {
|
||||
pub(crate) async fn set<T>(
|
||||
&mut self,
|
||||
&self,
|
||||
scopes: ScopeSet<'_, T>,
|
||||
token: TokenInfo,
|
||||
) -> anyhow::Result<()>
|
||||
|
||||
Reference in New Issue
Block a user