pub struct TokenService<Store> { /* private fields */ }Expand description
Issues rotating refresh families and checks stateful access revocation.
Implementations§
Source§impl<Store> TokenService<Store>where
Store: TokenStore,
impl<Store> TokenService<Store>where
Store: TokenStore,
Sourcepub fn new(
jwt: JwtManager,
store: Arc<Store>,
refresh_ttl: Duration,
) -> Result<TokenService<Store>, TokenError>
pub fn new( jwt: JwtManager, store: Arc<Store>, refresh_ttl: Duration, ) -> Result<TokenService<Store>, TokenError>
§Errors
Returns an error when refresh TTL is zero.
Sourcepub async fn issue<T>(
&self,
subject: impl Into<String>,
custom: T,
) -> Result<TokenPair, TokenError>where
T: Serialize,
pub async fn issue<T>(
&self,
subject: impl Into<String>,
custom: T,
) -> Result<TokenPair, TokenError>where
T: Serialize,
Issue a new access token and refresh family.
§Errors
Returns an error for invalid claims, clock failure, or persistence failure.
Sourcepub async fn refresh(
&self,
refresh_token: &str,
) -> Result<TokenPair, TokenError>
pub async fn refresh( &self, refresh_token: &str, ) -> Result<TokenPair, TokenError>
Rotate a refresh token exactly once. Reuse revokes the whole family.
§Errors
Returns an error for malformed/expired/reused tokens or persistence failure.
Sourcepub async fn verify_access<T>(
&self,
token: &str,
) -> Result<JwtClaims<T>, TokenError>where
T: DeserializeOwned,
pub async fn verify_access<T>(
&self,
token: &str,
) -> Result<JwtClaims<T>, TokenError>where
T: DeserializeOwned,
Verify cryptographic claims plus access-token and family revocation state.
§Errors
Returns an error for invalid or revoked access tokens.
Sourcepub async fn revoke_access(&self, token: &str) -> Result<(), TokenError>
pub async fn revoke_access(&self, token: &str) -> Result<(), TokenError>
Revoke one access token until its expiration.
§Errors
Returns an error when the access token is invalid or persistence fails.
Sourcepub async fn revoke_family(
&self,
family_id: impl Into<String>,
) -> Result<(), TokenError>
pub async fn revoke_family( &self, family_id: impl Into<String>, ) -> Result<(), TokenError>
Revoke a complete refresh family and every family-bound access token.
§Errors
Returns an error when the clock is invalid or persistence fails.
Sourcepub async fn purge_expired(&self) -> Result<(), TokenError>
pub async fn purge_expired(&self) -> Result<(), TokenError>
Remove expired refresh and revocation records.
§Errors
Returns an error when the clock is invalid or persistence fails.
Trait Implementations§
Source§impl<Store> Clone for TokenService<Store>
impl<Store> Clone for TokenService<Store>
Source§fn clone(&self) -> TokenService<Store>
fn clone(&self) -> TokenService<Store>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more