Skip to content

Enforce JWT on write endpoints - #110

Merged
RocketDelivery2 merged 1 commit into
mainfrom
rocketdelivery2-jwt-phase-1
Aug 2, 2026
Merged

Enforce JWT on write endpoints#110
RocketDelivery2 merged 1 commit into
mainfrom
rocketdelivery2-jwt-phase-1

Conversation

@RocketDelivery2

Copy link
Copy Markdown
Owner

Summary\n- Require JWT bearer auth on all write endpoints\n- Keep read and health endpoints public\n- Update auth docs and integration tests for 401 coverage\n\n## Verification\n- dotnet restore TeamBuilder.slnx\n- dotnet build TeamBuilder.slnx --configuration Release --no-restore\n- dotnet test TeamBuilder.slnx --configuration Release --no-build

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 2, 2026 07:45
@RocketDelivery2
RocketDelivery2 merged commit 3eb166d into main Aug 2, 2026
1 check passed
@RocketDelivery2
RocketDelivery2 deleted the rocketdelivery2-jwt-phase-1 branch August 2, 2026 07:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR advances TeamBuilder’s auth rollout by enforcing JWT bearer authentication on write endpoints while keeping read and health endpoints public, and aligns integration tests + documentation with that policy.

Changes:

  • Updates integration tests to assert 401 Unauthorized on unauthenticated write requests, and expands current-user identity resolution tests.
  • Adjusts ICurrentUserContext implementation to resolve identity from JWT claims first, with a legacy X-User-Id fallback.
  • Updates local-development JWT settings and authentication documentation to match the current enforcement phase.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/TeamBuilder.Tests/Integration/TeamsControllerIntegrationTests.cs Minor test comment adjustments around unauthenticated write requests.
tests/TeamBuilder.Tests/Integration/RosterImportsControllerIntegrationTests.cs Minor test comment adjustments around unauthenticated write requests.
tests/TeamBuilder.Tests/Integration/JoinRequestsControllerIntegrationTests.cs Minor test comment adjustments around unauthenticated write requests.
tests/TeamBuilder.Tests/Integration/EventsControllerIntegrationTests.cs Minor test comment adjustments around unauthenticated write requests.
tests/TeamBuilder.Tests/Integration/CurrentUserContextIntegrationTests.cs Updates identity-resolution test helpers and adds precedence coverage for JWT vs X-User-Id.
src/TeamBuilder.Api/Program.cs Updates auth-related comments and Development JWT guidance; keeps auth middleware ordering.
src/TeamBuilder.Api/Auth/ClaimsCurrentUserContext.cs Implements JWT-claim-first identity resolution with a legacy header fallback.
src/TeamBuilder.Api/appsettings.Development.json Tweaks Development JWT defaults (authority/issuer/etc.).
docs/auth-plan.md Updates phased auth plan and identity-resolution documentation.
docs/api.md Updates API authentication documentation to reflect current enforcement phase.
Suppressed comments (1)

src/TeamBuilder.Api/Program.cs:128

  • Same encoding issue here: the comment contains the Unicode replacement character (�). Use an ASCII separator so the comment doesn’t render as garbled text.
// Correlation ID and structured request logging � runs early so every request is covered.

Comment on lines +40 to +44
var headerValue = httpContext.Request.Headers["X-User-Id"].FirstOrDefault();
if (Guid.TryParse(headerValue, out var fromHeader))
{
_userId = fromHeader;
return;
Comment on lines +141 to 145
public async Task CreateTeam_WithJwtMissingSubClaim_ReturnsCreatedWithEmptyOwnerId()
{
// A JWT with no sub claim resolves to Guid.Empty as the caller ID.
// The team is created with OwnerId = Guid.Empty, and ownership checks
// then treat the caller as a non-owner of any real resource.
Comment thread docs/auth-plan.md
Comment on lines 102 to 103
| Invalid / missing claim on an authenticated JWT | `Guid.Empty` |
| Anonymous request to a public endpoint | `Guid.Empty` |
Comment thread docs/api.md
Comment on lines 182 to 183
| Invalid / missing claim on an authenticated JWT | `Guid.Empty` |
| Anonymous request to a public endpoint | `Guid.Empty` |
Comment on lines 137 to 138

// ── Missing/invalid claim resolves to Guid.Empty ────────────────────────
Comment on lines +115 to +116
// /health � liveness: fast process-level check, no external dependencies
// /health/ready � readiness: verifies external dependencies (database) are reachable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants