Skip to content

Commit 34971a9

Browse files
authored
Document server options for UltimateAuth configuration
Added documentation for configuring server options in UltimateAuth, including usage examples and key takeaways.
1 parent 807fe59 commit 34971a9

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# 🧩 Server Options
2+
3+
UltimateAuth is configured primarily through **Server Options**.
4+
5+
👉 This is the main entry point for configuring authentication behavior.
6+
7+
## 🧠 What Are Server Options?
8+
9+
Server options define how UltimateAuth behaves **inside your application**.
10+
11+
They control:
12+
13+
- Authentication behavior
14+
- Security policies
15+
- Token issuance
16+
- Session lifecycle
17+
- Endpoint exposure
18+
19+
<br>
20+
21+
## ⚙️ Basic Usage
22+
23+
You configure server options in `Program.cs`:
24+
25+
```csharp
26+
builder.Services.AddUltimateAuthServer(o =>
27+
{
28+
o.Login.MaxFailedAttempts = 5;
29+
o.Session.IdleTimeout = TimeSpan.FromDays(7);
30+
});
31+
```
32+
33+
---
34+
35+
You can also use `appsettings.json`:
36+
37+
```json
38+
{
39+
"UltimateAuth": {
40+
"Server": {
41+
"Login": {
42+
"MaxFailedAttempts": 5
43+
},
44+
"Session": {
45+
"IdleTimeout": "07.00.00.00"
46+
}
47+
}
48+
}
49+
}
50+
```
51+
52+
👉 `appsettings.json` overrides `Program.cs`
53+
54+
## 🧩 Core Composition
55+
56+
Server options include Core behavior:
57+
58+
- Login
59+
- Session
60+
- Token
61+
- PKCE
62+
- Multi-tenancy
63+
64+
👉 These are defined in Core
65+
66+
👉 But configured via Server
67+
68+
<br>
69+
70+
## ⚠️ Important: You Don’t Configure Modes Directly
71+
72+
UltimateAuth does NOT expect you to select a single auth mode.
73+
74+
Instead:
75+
76+
👉 Mode is resolved at runtime
77+
78+
<br>
79+
80+
## 🛡 Allowed Modes (Guardrail)
81+
82+
```csharp
83+
o.AllowedModes = new[]
84+
{
85+
UAuthMode.Hybrid,
86+
UAuthMode.PureOpaque
87+
};
88+
```
89+
90+
👉 This does NOT select a mode
91+
👉 It restricts which modes are allowed
92+
93+
If a resolved mode is not allowed:
94+
95+
👉 Request fails early
96+
97+
<br>
98+
99+
## ⚡ Runtime Behavior (Effective Options)
100+
101+
Server options are not used directly.
102+
103+
They are transformed into:
104+
105+
👉 `EffectiveUAuthServerOptions`
106+
107+
This happens per request:
108+
109+
- Mode is resolved
110+
- Defaults are applied
111+
- Overrides are applied
112+
113+
👉 What actually runs is **Effective Options**
114+
115+
<br>
116+
117+
## 🔄 Mode-Based Defaults
118+
119+
Each auth mode applies different defaults automatically:
120+
121+
- PureOpaque → session-heavy
122+
- Hybrid → session + token
123+
- PureJwt → token-only
124+
125+
126+
👉 You don’t need to manually configure everything
127+
128+
<br>
129+
130+
## 🎛 Endpoint Control
131+
132+
You can control which features are enabled:
133+
134+
```csharp
135+
o.Endpoints.Authentication = true;
136+
o.Endpoints.Session = true;
137+
o.Endpoints.Authorization = true;
138+
```
139+
140+
141+
You can also disable specific actions:
142+
143+
```csharp
144+
o.Endpoints.DisabledActions.Add("UAuthActions.Users.Create.Anonymous");
145+
```
146+
147+
👉 Useful for API hardening
148+
149+
<br>
150+
151+
## 🍪 Cookie & Transport Behavior
152+
153+
Server options define how credentials are transported:
154+
155+
- Cookies
156+
- Headers
157+
- Tokens
158+
159+
👉 Unsafe combinations are rejected at startup
160+
161+
<br>
162+
163+
## 🌐 Hub Configuration
164+
165+
If using UAuthHub:
166+
167+
```csharp
168+
o.HubDeploymentMode = UAuthHubDeploymentMode.Integrated;
169+
```
170+
171+
👉 Defines how auth server is deployed
172+
173+
<br>
174+
175+
## 🔁 Session Resolution
176+
177+
Controls how session IDs are extracted:
178+
179+
- Cookie
180+
- Header
181+
- Bearer
182+
- Query
183+
184+
👉 Fully configurable
185+
186+
<br>
187+
188+
## 🧠 Mental Model
189+
190+
If you remember one thing:
191+
192+
👉 Server options define **what is allowed**
193+
👉 Runtime determines **what is used**
194+
195+
## 📌 Key Takeaways
196+
197+
- Server options are the main configuration entry
198+
- Core behavior is configured via server
199+
- Modes are not selected manually
200+
- Effective options are computed per request
201+
- Security is enforced by design
202+
203+
---
204+
205+
## ➡️ Next Step
206+
207+
Continue to **Client Options**

0 commit comments

Comments
 (0)