Skip to content

Commit 23934b6

Browse files
authored
Add documentation for token behavior in UltimateAuth
Document the behavior and characteristics of tokens in UltimateAuth, including types, modes, access and refresh tokens, security model, and key takeaways.
1 parent 703452a commit 23934b6

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# 🎟 Token Behavior
2+
In UltimateAuth, tokens are not the foundation of authentication.
3+
4+
👉 They are **derived artifacts of a session**
5+
6+
## 🧠 Rethinking Tokens
7+
In traditional systems:
8+
9+
- Token = identity
10+
- Token = authentication
11+
12+
In UltimateAuth:
13+
14+
👉 Session = identity
15+
👉 Token = transport mechanism
16+
17+
> Tokens do not define identity
18+
> → Sessions do
19+
20+
## 🧩 Token Types
21+
UltimateAuth supports two main token types:
22+
23+
### 🔹 Opaque Tokens
24+
- Random, non-decodable values
25+
- Stored and validated on the server
26+
- Typically reference a session
27+
28+
👉 Used in:
29+
30+
- PureOpaque
31+
- Hybrid
32+
33+
### 🔹 JWT (JSON Web Tokens)
34+
- Self-contained tokens
35+
- Include claims and metadata
36+
- Signed and verifiable without server lookup
37+
38+
👉 Used in:
39+
40+
- SemiHybrid
41+
- PureJwt
42+
43+
<br>
44+
45+
## ⚖️ Mode-Based Behavior
46+
Token behavior depends on the authentication mode:
47+
48+
| Mode | Access Token | Refresh Token | Behavior |
49+
|-------------|---------------|----------------|---------------------------|
50+
| PureOpaque ||| Session-only |
51+
| Hybrid | ✔ (opaque/JWT)|| Session + token |
52+
| SemiHybrid | ✔ (JWT) || JWT + session metadata |
53+
| PureJwt | ✔ (JWT) || Fully stateless |
54+
55+
👉 UltimateAuth selects behavior automatically
56+
57+
<br>
58+
59+
## 🔑 Access Tokens
60+
Access tokens represent:
61+
62+
👉 A **temporary access grant**
63+
64+
### Characteristics
65+
- Short-lived
66+
- Mode-dependent format
67+
- May contain session reference (`sid`)
68+
- May include claims
69+
70+
### Important
71+
Access token is NOT the source of truth.
72+
73+
👉 It reflects session state, not replaces it
74+
75+
## 🔄 Refresh Tokens
76+
Refresh tokens represent:
77+
78+
👉 A **continuation mechanism**
79+
80+
### Characteristics
81+
- Long-lived
82+
- Stored as hashed values
83+
- Bound to session and optionally chain
84+
- Rotated on use
85+
86+
### Lifecycle
87+
Issued → Used → Replaced → Revoked
88+
89+
👉 Old tokens are invalidated on rotation
90+
91+
<br>
92+
93+
## 🔐 Security Model
94+
95+
### 🔁 Rotation
96+
Each refresh:
97+
98+
- Invalidates previous token
99+
- Issues a new token
100+
101+
👉 Prevents replay attacks
102+
103+
### 🚨 Reuse Detection
104+
If a token is reused:
105+
106+
- Chain may be revoked
107+
- Session may be revoked
108+
109+
👉 Strong forward security
110+
111+
### 🔗 Session Binding
112+
Refresh tokens include:
113+
114+
- SessionId
115+
- ChainId (optional)
116+
117+
👉 Prevents cross-context usage
118+
119+
### 🔒 Hashed Storage
120+
Tokens are:
121+
122+
- Never stored as plaintext
123+
- Hashed using secure algorithms
124+
125+
👉 Reduces breach impact
126+
127+
<br>
128+
129+
## 🔄 Token Issuance
130+
Tokens are issued during:
131+
132+
- Login
133+
- Refresh
134+
135+
### Access Token
136+
- May be opaque or JWT
137+
- Includes identity and optional session reference
138+
139+
### Refresh Token
140+
- Always opaque
141+
- Persisted in secure store
142+
- Used only for rotation
143+
144+
<br>
145+
146+
## 🧠 Mental Model
147+
If you remember one thing:
148+
149+
👉 Tokens are not identity
150+
👉 They are projections of a session
151+
152+
## 📌 Key Takeaways
153+
- Session is the source of truth
154+
- Tokens are optional and mode-dependent
155+
- Opaque tokens require server validation
156+
- JWT tokens allow stateless access
157+
- Refresh tokens enable secure continuation
158+
- Token rotation ensures forward security
159+
160+
## ➡️ Next Step
161+
162+
Continue to Device Management

0 commit comments

Comments
 (0)