TaskHub.Shared

Security

Security in TaskHub.Shared covers authentication (who is the caller?), authorization (what may they do?), and identity propagation (carrying that context across service hops). Every public endpoint is protected; every internal call carries the caller’s token forward.

🎯 Design Goals

  1. JWT everywhere. Internal services trust each other via signed bearer tokens β€” no shared secrets, no IP allow-listing.
  2. Identity is ambient. Once authenticated, IUserService.UserId is available anywhere in the request scope. No threading the user ID through method signatures.
  3. Status checks at the edge. Blocked / deleted / disabled users are filtered in middleware, not in every handler.
  4. Result-typed failures. Authorization failures return a Result with a stable code, not an exception β€” clients see the same shape as any other failure.

πŸ“¦ Modules

Module Purpose
Authorization Abstractions ITokenService, IUserService β€” the contracts your code depends on.
Authorization Identity JWT bearer setup, UserStatusMiddleware, token generation, options.

🧭 The Request Lifecycle

   Client ──[Authorization: Bearer eyJ…]──► Service
                                               β”‚
                                               β–Ό
                          JwtBearer middleware (signature, expiry, audience)
                                               β”‚
                                               β–Ό
                          UserStatusMiddleware (blocked/deleted/disabled?)
                                               β”‚
                                               β–Ό
                          IUserService (scoped β€” UserId available)
                                               β”‚
                                               β–Ό
                          Endpoint / Command Pipeline

Internal calls forward the same bearer via BearerTokenHandler (see Networking) β€” the downstream service sees the same UserId.

βš™οΈ Minimal Configuration

"Jwt": {
  "SigningKey": "<base64 256-bit key>",
  "Issuer": "task-hub",
  "Audience": "task-hub-users",
  "ValidateSigningKey": true,
  "ValidateAudience": true,
  "ValidateIssuer": true,
  "ValidateLifetime": true,
  "ClockSkew": 300000
}

The FullHostBuilder calls AddAppIdentity() automatically when this section is present.

βœ… Best Practices

πŸ”— See Also