|
16 | 16 | | MongoDB Driver | 2.x | 3.0+ | |
17 | 17 | | HttpContextAccessor | Manual `services.AddHttpContextAccessor()` | Auto-registered by `AddBewit()` | |
18 | 18 | | Startup validation | None | `ServerControlled` without nonce repo fails at startup | |
| 19 | +| Token extraction | Hardcoded header/query per extension | Unified `BewitTokenExtractionOptions` with header + query fallback | |
| 20 | +| HotChocolate setup | `UseBewitTokenHeaderExtraction()` | `UseBewitTokenExtraction()` | |
19 | 21 |
|
20 | 22 | ## DI Registration Migration |
21 | 23 |
|
@@ -245,3 +247,55 @@ services.AddBewit(bewit => |
245 | 247 | | `PayloadBuilder.UseSlidingWindow(TimeSpan)` | `ConfigureOptions(o => o.SlidingWindow = ...)` | |
246 | 248 | | `PayloadBuilder.WithTokenDuration(TimeSpan)` | `ConfigureOptions(o => o.TokenDuration = ...)` | |
247 | 249 | | `UseMongoPersistence(config, ...)` | `UseMongoDb(...)` on `BewitBuilder` or `PayloadBuilder<T>` | |
| 250 | +| `BewitTokenConstants` | `BewitTokenExtractionOptions` (configurable via options pattern) | |
| 251 | +| `UseBewitTokenHeaderExtraction()` | `UseBewitTokenExtraction()` | |
| 252 | + |
| 253 | +## Token Extraction Migration |
| 254 | + |
| 255 | +In v6.x, the HotChocolate extension used a hardcoded `bewitToken` header and the Http extension used a hardcoded `bewit` query parameter. These were not configurable. |
| 256 | + |
| 257 | +In v7.0, all extensions (HotChocolate, Http, Mvc) use `BewitTokenExtractionOptions` — a shared, configurable options class that follows the standard .NET options pattern. |
| 258 | + |
| 259 | +### Before (v6.x) |
| 260 | +```csharp |
| 261 | +// HotChocolate — header only, hardcoded name |
| 262 | +app.UseBewitTokenHeaderExtraction(); |
| 263 | + |
| 264 | +// Http — query param only, hardcoded name |
| 265 | +app.UseBewitEndpointAuthorization<T>(); |
| 266 | + |
| 267 | +// Mvc — query param only, hardcoded name |
| 268 | +[BewitUrlAuthorization] |
| 269 | +``` |
| 270 | + |
| 271 | +### After (v7.0) |
| 272 | +```csharp |
| 273 | +// HotChocolate — reads header first, then query param |
| 274 | +app.UseBewitTokenExtraction(); |
| 275 | + |
| 276 | +// Http — reads header first, then query param |
| 277 | +app.UseBewitEndpointAuthorization<T>(); |
| 278 | + |
| 279 | +// Mvc — reads header first, then query param |
| 280 | +[BewitUrlAuthorization] |
| 281 | +``` |
| 282 | + |
| 283 | +All three now check **header first, then fall back to query parameter**. Default names are unchanged (`bewitToken` header, `bewit` query param), so existing consumers work without config changes. |
| 284 | + |
| 285 | +### Custom token extraction |
| 286 | +```csharp |
| 287 | +services.AddBewit(bewit => |
| 288 | +{ |
| 289 | + bewit.ConfigureTokenExtraction(o => |
| 290 | + { |
| 291 | + o.HeaderName = "X-Custom-Token"; |
| 292 | + o.QueryParamName = "token"; |
| 293 | + }); |
| 294 | + // or from appsettings.json: |
| 295 | + bewit.BindTokenExtractionConfiguration("Bewit:TokenExtraction"); |
| 296 | + |
| 297 | + bewit.AddPayload<string>(); |
| 298 | +}); |
| 299 | +``` |
| 300 | + |
| 301 | +`BewitTokenExtractionOptions` supports full .NET options layering: `Bind` → `Configure` → `PostConfigure`, with `ValidateDataAnnotations` and `ValidateOnStart`. |
0 commit comments