pub struct SessionRenewer<R, A, G, H> { /* private fields */ }Expand description
Renews existing sessions using refresh-token rotation.
Use this service when a client presents a refresh token and you need to decide whether renewal is needed, coordinate leases, rotate token state, and produce replacement tokens.
§Examples
use webgates_sessions::config::SessionConfig;
use webgates_sessions::services::SessionRenewer;
use webgates_sessions::tokens::{
OpaqueRefreshTokenGenerator, RefreshTokenLength, Sha256RefreshTokenHasher,
TokenPairIssuer, AuthToken, AuthTokenIssuer,
};
use webgates_sessions::session::Session;
#[derive(Debug, Clone, Copy)]
struct NoopIssuer;
impl AuthTokenIssuer<Session> for NoopIssuer {
type Error = webgates_sessions::errors::TokenError;
fn issue_auth_token(
&self,
s: &Session,
) -> impl std::future::Future<Output = Result<AuthToken, Self::Error>> + Send {
std::future::ready(AuthToken::new(format!("auth-{}", s.subject_id)))
}
}
let length = RefreshTokenLength::new(64).unwrap();
let token_pair_issuer = TokenPairIssuer::new(
NoopIssuer,
OpaqueRefreshTokenGenerator::new(length),
Sha256RefreshTokenHasher,
);
let renewer = SessionRenewer::new(
SessionConfig::default(),
Noop,
token_pair_issuer,
)
.unwrap();Implementations§
Source§impl<R, A, G, H> SessionRenewer<R, A, G, H>
impl<R, A, G, H> SessionRenewer<R, A, G, H>
Sourcepub fn new(
config: SessionConfig,
repository: R,
token_pair_issuer: TokenPairIssuer<A, G, H>,
) -> ConfigResult<Self>
pub fn new( config: SessionConfig, repository: R, token_pair_issuer: TokenPairIssuer<A, G, H>, ) -> ConfigResult<Self>
Creates a new session renewer.
§Errors
Returns a configuration error when config is internally inconsistent.
Source§impl<R, A, G, H> SessionRenewer<R, A, G, H>where
R: SessionRepository,
A: AuthTokenIssuer<Session>,
G: RefreshTokenGenerator,
H: RefreshTokenHasher,
impl<R, A, G, H> SessionRenewer<R, A, G, H>where
R: SessionRepository,
A: AuthTokenIssuer<Session>,
G: RefreshTokenGenerator,
H: RefreshTokenHasher,
Sourcepub async fn renew_session(
&self,
auth_token_state: AuthTokenState,
requirement: RenewalRequirement,
refresh_token: &RefreshTokenPlaintext,
now: SystemTime,
) -> Result<RenewalOutcome>
pub async fn renew_session( &self, auth_token_state: AuthTokenState, requirement: RenewalRequirement, refresh_token: &RefreshTokenPlaintext, now: SystemTime, ) -> Result<RenewalOutcome>
Attempts to renew a session using the presented refresh token.
Valid auth tokens that are not yet near expiry short-circuit to
RenewalOutcome::NotNeeded without touching persistence.
§Errors
Returns a session error when hashing, repository access, token issuance, or family revocation fails.
Trait Implementations§
Source§impl<R: Clone, A: Clone, G: Clone, H: Clone> Clone for SessionRenewer<R, A, G, H>
impl<R: Clone, A: Clone, G: Clone, H: Clone> Clone for SessionRenewer<R, A, G, H>
Source§fn clone(&self) -> SessionRenewer<R, A, G, H>
fn clone(&self) -> SessionRenewer<R, A, G, H>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<R, A, G, H> Freeze for SessionRenewer<R, A, G, H>
impl<R, A, G, H> RefUnwindSafe for SessionRenewer<R, A, G, H>
impl<R, A, G, H> Send for SessionRenewer<R, A, G, H>
impl<R, A, G, H> Sync for SessionRenewer<R, A, G, H>
impl<R, A, G, H> Unpin for SessionRenewer<R, A, G, H>
impl<R, A, G, H> UnsafeUnpin for SessionRenewer<R, A, G, H>
impl<R, A, G, H> UnwindSafe for SessionRenewer<R, A, G, H>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more