pub struct SessionIssuer<R, A, G, H> { /* private fields */ }Expand description
Issues new session state and token pairs.
Use this service after successful authentication when you want to create a session-backed login result.
§Examples
use webgates_sessions::config::SessionConfig;
use webgates_sessions::services::SessionIssuer;
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 issuer = SessionIssuer::new(
SessionConfig::default(),
Noop,
token_pair_issuer,
)
.unwrap();Implementations§
Source§impl<R, A, G, H> SessionIssuer<R, A, G, H>
impl<R, A, G, H> SessionIssuer<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 issuer from validated configuration, a repository, and a token-pair issuer.
§Errors
Returns a configuration error when config is internally inconsistent.
Source§impl<R, A, G, H> SessionIssuer<R, A, G, H>where
R: SessionRepository,
A: AuthTokenIssuer<Session>,
G: RefreshTokenGenerator,
H: RefreshTokenHasher,
impl<R, A, G, H> SessionIssuer<R, A, G, H>where
R: SessionRepository,
A: AuthTokenIssuer<Session>,
G: RefreshTokenGenerator,
H: RefreshTokenHasher,
Sourcepub async fn issue_session(
&self,
subject_id: impl Into<String>,
now: SystemTime,
) -> Result<IssuedSession>
pub async fn issue_session( &self, subject_id: impl Into<String>, now: SystemTime, ) -> Result<IssuedSession>
Issues a new session for subject_id, persists it, and returns the
issued session plus tokens.
§Errors
Returns a session error when token issuance or persistence fails.
Trait Implementations§
Source§impl<R: Clone, A: Clone, G: Clone, H: Clone> Clone for SessionIssuer<R, A, G, H>
impl<R: Clone, A: Clone, G: Clone, H: Clone> Clone for SessionIssuer<R, A, G, H>
Source§fn clone(&self) -> SessionIssuer<R, A, G, H>
fn clone(&self) -> SessionIssuer<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 SessionIssuer<R, A, G, H>
impl<R, A, G, H> RefUnwindSafe for SessionIssuer<R, A, G, H>
impl<R, A, G, H> Send for SessionIssuer<R, A, G, H>
impl<R, A, G, H> Sync for SessionIssuer<R, A, G, H>
impl<R, A, G, H> Unpin for SessionIssuer<R, A, G, H>
impl<R, A, G, H> UnsafeUnpin for SessionIssuer<R, A, G, H>
impl<R, A, G, H> UnwindSafe for SessionIssuer<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