Enforce JWT on write endpoints - #110
Merged
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
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 Unauthorizedon unauthenticated write requests, and expands current-user identity resolution tests. - Adjusts
ICurrentUserContextimplementation to resolve identity from JWT claims first, with a legacyX-User-Idfallback. - 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 on lines
102
to
103
| | Invalid / missing claim on an authenticated JWT | `Guid.Empty` | | ||
| | Anonymous request to a public endpoint | `Guid.Empty` | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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