Skip to content

Commit 73d792b

Browse files
authored
Add authentication model documentation for UltimateAuth
Added comprehensive documentation on the authentication model for UltimateAuth, detailing the concepts of Root, Chain, and Session, and their interactions.
1 parent 52ce53e commit 73d792b

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed

docs/fundamentals/auth-model.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# 🧠 Authentication Model
2+
3+
UltimateAuth is built around a simple but powerful idea:
4+
5+
> Authentication is not just a token.
6+
> It is a **structured, server-controlled session model**.
7+
8+
At the core of this model are three concepts:
9+
10+
- **Root**
11+
- **Chain**
12+
- **Session**
13+
14+
Together, they form what we call:
15+
16+
👉 **Authentication Lineage**
17+
18+
<br>
19+
20+
## 🔑 The Big Picture
21+
22+
Instead of treating authentication as a single token or cookie, UltimateAuth models it as a hierarchy:
23+
24+
```
25+
Root (user authority)
26+
├── Chain (device context)
27+
│ ├── Session (login instance)
28+
│ ├── Session
29+
30+
├── Chain
31+
│ ├── Session (login instance)
32+
```
33+
34+
Each level has a distinct responsibility.
35+
36+
<br>
37+
38+
## 🧩 Root — The Authority
39+
40+
**Root** represents the authentication authority of a user within a tenant.
41+
42+
- There is **only one active Root per user per tenant**
43+
- It defines the **global security state**
44+
- It controls all chains and sessions
45+
46+
### What Root Does
47+
48+
- Tracks security version (security epoch)
49+
- Invalidates all sessions when needed
50+
- Acts as the **source of truth**
51+
52+
### Example
53+
54+
If a user changes their password:
55+
56+
👉 Root is updated
57+
👉 All existing sessions can become invalid
58+
59+
<br>
60+
61+
## 🔗 Chain — The Device Context
62+
63+
**Chain** represents a device or client context.
64+
65+
- Each device typically has its own chain
66+
- Multiple logins from the same device belong to the same chain
67+
68+
👉 Think of Chain as:
69+
70+
> “Where is the user logged in from?”
71+
72+
### What Chain Does
73+
74+
- Groups sessions by device
75+
- Enables **device-level control**
76+
- Allows actions like:
77+
78+
- Logout from one device
79+
- Revoke a specific device
80+
81+
<br>
82+
83+
## 🧾 Session — The Authentication Instance
84+
85+
**Session** is the actual authentication instance.
86+
87+
- Created when the user logs in
88+
- Represents a single authenticated state
89+
- Carries a snapshot of the Root security version
90+
91+
👉 This is what gets validated on each request.
92+
93+
### What Session Does
94+
95+
- Proves the user is authenticated
96+
- Can be refreshed, revoked, or expired
97+
- Is tied to a specific chain
98+
99+
<br>
100+
101+
## 🔄 How They Work Together
102+
103+
When a user logs in:
104+
105+
1. Root is resolved (or created)
106+
2. A Chain is identified (device context)
107+
3. A new Session is created
108+
109+
`Login → Root → Chain → Session`
110+
111+
112+
On each request:
113+
114+
1. Session is validated
115+
2. Chain context is checked
116+
3. Root security version is verified
117+
118+
👉 If any level is invalid → authentication fails
119+
120+
<br>
121+
122+
## 🛡 Why This Model Matters
123+
124+
Traditional systems rely on:
125+
126+
- Cookies
127+
- JWT tokens
128+
- Stateless validation
129+
130+
These approaches have limitations:
131+
132+
- No real session control
133+
- Weak revocation
134+
- No device awareness
135+
136+
---
137+
138+
UltimateAuth solves this by:
139+
140+
### ✔ Server-Controlled Authentication
141+
142+
- Sessions are always validated server-side
143+
- No blind trust in tokens
144+
145+
### ✔ Instant Revocation
146+
147+
- Revoke a session → immediate effect
148+
- Revoke a chain → device logged out
149+
- Revoke root → disable user (global logout)
150+
151+
### ✔ Device Awareness
152+
153+
- Each device has its own chain
154+
- Sessions are bound to context
155+
156+
### ✔ Strong Security Model
157+
158+
- Session carries Root security version
159+
- Old sessions automatically become invalid
160+
161+
<br>
162+
163+
## 🧠 Mental Model
164+
165+
If you remember only one thing, remember this:
166+
167+
👉 **Root = authority**
168+
👉 **Chain = device**
169+
👉 **Session = login**
170+
171+
## 📌 Key Takeaways
172+
173+
- Authentication is not just a token
174+
- Sessions are first-class citizens
175+
- The server always remains in control
176+
- Device and security context are built-in
177+
178+
## ➡️ Next Step
179+
180+
Now that you understand the core model:
181+
182+
👉 Continue to **Flow-Based Authentication**

0 commit comments

Comments
 (0)