|
| 1 | +# 🧬 Session Lifecycle |
| 2 | +UltimateAuth is built around a structured session model. |
| 3 | + |
| 4 | +👉 Authentication is not a token |
| 5 | +👉 It is a **hierarchical session system** |
| 6 | + |
| 7 | +## 🧠 Core Model |
| 8 | + |
| 9 | +UltimateAuth defines three core entities: |
| 10 | +``` |
| 11 | +Root → Chain → Session |
| 12 | +``` |
| 13 | + |
| 14 | +### 🔹 Root (Identity Authority) |
| 15 | +- One per user |
| 16 | +- Represents global authentication state |
| 17 | +- Holds security version |
| 18 | + |
| 19 | +👉 Root defines **who the user is** |
| 20 | + |
| 21 | +### 📱 Chain (Device Context) |
| 22 | +- One per device |
| 23 | +- Represents a device-bound identity context |
| 24 | +- Tracks activity (LastSeenAt) |
| 25 | +- Manages session rotation and touch |
| 26 | + |
| 27 | +👉 A chain is a **trusted device boundary** |
| 28 | + |
| 29 | +### 🔑 Session (Authentication Instance) |
| 30 | +- Created on login |
| 31 | +- Represents a single authentication event |
| 32 | +- Has expiration and revocation state |
| 33 | + |
| 34 | +👉 A session is a **proof of authentication** |
| 35 | + |
| 36 | +<br> |
| 37 | + |
| 38 | +## 🔗 Relationship |
| 39 | +``` |
| 40 | +User |
| 41 | +└── Root |
| 42 | +└── Chain (Device) |
| 43 | +└── Session (Instance) |
| 44 | +``` |
| 45 | + |
| 46 | +👉 Each level adds more specificity: |
| 47 | + |
| 48 | +- Root → identity |
| 49 | +- Chain → device |
| 50 | +- Session → login instance |
| 51 | + |
| 52 | +<br> |
| 53 | + |
| 54 | +## 🔄 Lifecycle Overview |
| 55 | + |
| 56 | +### 1️⃣ Creation (Login) |
| 57 | +When a user logs in: |
| 58 | + |
| 59 | +- Root is created (if not exists) |
| 60 | +- Chain is resolved or created |
| 61 | +- Session is issued |
| 62 | + |
| 63 | +### 2️⃣ Active Usage |
| 64 | +During normal operation: |
| 65 | + |
| 66 | +- Session is validated |
| 67 | +- Chain `LastSeenAt` is updated (touch) |
| 68 | +- Sliding expiration may apply |
| 69 | + |
| 70 | +👉 Activity updates the **chain**, not just the session |
| 71 | + |
| 72 | +### 3️⃣ Refresh |
| 73 | +Depending on mode: |
| 74 | + |
| 75 | +#### Session-Based (PureOpaque) |
| 76 | +- Session remains |
| 77 | +- Chain is touched |
| 78 | + |
| 79 | +#### Token-Based (Hybrid / JWT) |
| 80 | +- Session continues |
| 81 | +- Tokens are rotated |
| 82 | +- Chain rotation count increases |
| 83 | + |
| 84 | +👉 Chain tracks behavior: |
| 85 | + |
| 86 | +- RotationCount |
| 87 | +- TouchCount |
| 88 | + |
| 89 | +### 4️⃣ Expiration |
| 90 | +A session may expire due to: |
| 91 | + |
| 92 | +- Lifetime expiration |
| 93 | +- Idle timeout |
| 94 | +- Absolute expiration |
| 95 | + |
| 96 | +👉 Expired ≠ revoked |
| 97 | + |
| 98 | +### 5️⃣ Revocation |
| 99 | +Revocation can occur at multiple levels: |
| 100 | + |
| 101 | +#### Session Revocation |
| 102 | +- Single session invalidated |
| 103 | + |
| 104 | +#### Chain Revocation |
| 105 | +- All sessions on device invalidated |
| 106 | +- Device trust reset |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +#### Root Revocation |
| 111 | + |
| 112 | +- All chains and sessions invalidated |
| 113 | +- Security version increased |
| 114 | + |
| 115 | +👉 Revocation is irreversible |
| 116 | + |
| 117 | +<br> |
| 118 | + |
| 119 | +## 🔐 Security Model |
| 120 | + |
| 121 | +### 🔒 Security Versioning |
| 122 | +Each root has: |
| 123 | +- `SecurityVersion` |
| 124 | + |
| 125 | +Each session stores: |
| 126 | +- `SecurityVersionAtCreation` |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +👉 If mismatch: |
| 131 | + |
| 132 | +```text |
| 133 | +Session becomes invalid |
| 134 | +``` |
| 135 | + |
| 136 | +### 🔗 Device Binding |
| 137 | +Each chain is tied to: |
| 138 | + |
| 139 | +- DeviceId |
| 140 | +- Platform |
| 141 | +- OS |
| 142 | +- Browser |
| 143 | + |
| 144 | +👉 Prevents cross-device misuse |
| 145 | + |
| 146 | +### 🔁 Rotation Tracking |
| 147 | +Chains track: |
| 148 | + |
| 149 | +- RotationCount |
| 150 | +- TouchCount |
| 151 | + |
| 152 | +👉 Enables: |
| 153 | + |
| 154 | +- replay detection |
| 155 | +- anomaly tracking |
| 156 | + |
| 157 | +### ⚙️ Lifecycle Configuration |
| 158 | +Session behavior is configurable: |
| 159 | + |
| 160 | +⏱ Lifetime |
| 161 | +- Default session duration |
| 162 | + |
| 163 | +🔄 Sliding Expiration |
| 164 | +- Extends session on activity |
| 165 | + |
| 166 | +💤 Idle Timeout |
| 167 | +- Invalidates inactive sessions |
| 168 | + |
| 169 | +📱 Device Limits |
| 170 | +- Max chains per user |
| 171 | +- Max sessions per chain |
| 172 | + |
| 173 | +👉 These are defined via UAuthSessionOptions |
| 174 | + |
| 175 | +<br> |
| 176 | + |
| 177 | +## 🧠 Mental Model |
| 178 | +If you remember one thing: |
| 179 | + |
| 180 | +👉 Authentication is a living structure |
| 181 | +👉 Not a static token |
| 182 | + |
| 183 | +## 📌 Key Takeaways |
| 184 | +- Sessions are part of a hierarchy |
| 185 | +- Device (chain) is a first-class concept |
| 186 | +- Root controls global security |
| 187 | +- Sessions are short-lived proofs |
| 188 | +- Chains manage lifecycle and activity |
| 189 | +- Revocation operates at multiple levels |
| 190 | + |
| 191 | +## ➡️ Next Step |
| 192 | + |
| 193 | +Continue to Token Behavior |
| 194 | + |
0 commit comments