Skip to main content

webgates_sessions/
logout.rs

1//! Session logout primitives.
2//!
3//! This module defines the framework-agnostic types that drive session
4//! revocation flows. Transport adapters remain responsible for extracting
5//! cookies, headers, and request metadata before calling into these models.
6
7use crate::session::{SessionFamilyId, SessionId};
8
9/// The requested scope of a logout operation.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub enum LogoutScope {
12    /// Revoke only the current session.
13    CurrentSession,
14    /// Revoke every session that belongs to the same session family.
15    SessionFamily,
16}
17
18/// Input required to revoke an existing session.
19///
20/// Higher-level adapters and services populate this value from the currently
21/// authenticated session context.
22///
23/// # Examples
24///
25/// ```
26/// use webgates_sessions::logout::{LogoutRequest, LogoutScope};
27/// use webgates_sessions::session::{SessionFamilyId, SessionId};
28///
29/// let session_id = SessionId::new();
30/// let family_id = SessionFamilyId::new();
31///
32/// // Revoke only the current session.
33/// let request = LogoutRequest::new(session_id, family_id, LogoutScope::CurrentSession);
34/// assert_eq!(request.scope, LogoutScope::CurrentSession);
35///
36/// // Revoke the entire session family (all devices).
37/// let request = LogoutRequest::new(session_id, family_id, LogoutScope::SessionFamily);
38/// assert_eq!(request.scope, LogoutScope::SessionFamily);
39/// ```
40#[derive(Debug, Clone, PartialEq, Eq, Hash)]
41pub struct LogoutRequest {
42    /// The session targeted by the logout operation.
43    pub session_id: SessionId,
44    /// The family that owns the targeted session.
45    pub family_id: SessionFamilyId,
46    /// The revocation scope to apply.
47    pub scope: LogoutScope,
48}
49
50impl LogoutRequest {
51    /// Creates a new logout request.
52    #[must_use]
53    pub fn new(session_id: SessionId, family_id: SessionFamilyId, scope: LogoutScope) -> Self {
54        Self {
55            session_id,
56            family_id,
57            scope,
58        }
59    }
60}
61
62/// Outcome produced by a logout operation.
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
64pub enum LogoutOutcome {
65    /// The current session was revoked.
66    CurrentSessionRevoked,
67    /// The full session family was revoked.
68    SessionFamilyRevoked,
69}