appcore_gateway/session.rs
1// =============================================================================
2// #######
3// ### ### F: session.rs
4// ## ## ## ## P: AppCore-Runtime
5// ## ##
6// C: 2026/07/26 08:53:09 by dnettoRaw
7// ## ## ## ## U: 2026/07/26 08:53:09 by dnettoRaw
8// ########### S: 1.0.1-rc.8
9// =============================================================================
10
11//! Session management and token context tracking.
12
13use appcore_types::TenantId;
14
15/// Represents an authenticated client session.
16#[derive(Debug, Clone)]
17pub struct GatewaySession {
18 /// Unique identifier for this session.
19 pub session_id: String,
20
21 /// Tenant scope constraint.
22 pub tenant_id: TenantId,
23
24 /// When the session was established (Unix epoch ms).
25 pub created_at_ms: u64,
26
27 /// When the session token expires (Unix epoch ms).
28 pub expires_at_ms: u64,
29
30 /// Subject derived from client credentials.
31 pub subject: Option<String>,
32}
33
34impl GatewaySession {
35 /// Creates a new gateway session.
36 pub fn new(
37 session_id: String,
38 tenant_id: TenantId,
39 created_at_ms: u64,
40 expires_at_ms: u64,
41 subject: Option<String>,
42 ) -> Self {
43 Self {
44 session_id,
45 tenant_id,
46 created_at_ms,
47 expires_at_ms,
48 subject,
49 }
50 }
51
52 /// Reports whether the session has expired relative to `now_ms`.
53 pub fn is_expired(&self, now_ms: u64) -> bool {
54 now_ms >= self.expires_at_ms
55 }
56}