Skip to content

Replace header-based userId with verified JWT sub claim (LEY-15)#12

Merged
ltyu merged 2 commits intomasterfrom
leyu00/ley-15-replace-header-based-userid-with-verified-jwt-sub-claim
Mar 18, 2026
Merged

Replace header-based userId with verified JWT sub claim (LEY-15)#12
ltyu merged 2 commits intomasterfrom
leyu00/ley-15-replace-header-based-userid-with-verified-jwt-sub-claim

Conversation

@ltyu
Copy link
Copy Markdown
Owner

@ltyu ltyu commented Mar 18, 2026

Summary

Replaces the unsafe x-authenticated-user-id header with the verified JWT sub claim injected by API Gateway after Auth0 token validation.

Changes

  • Add JwtClaims type to src/types.ts representing the Auth0 JWT authorizer claims shape
  • Add src/services/jwtAuthenticatedAppUserProvider.ts — reads userId from event.requestContext.authorizer.jwt.claims.sub, which is populated by API Gateway only after a valid JWT has been verified
  • Remove HeaderAuthenticatedAppUserProvider and the x-authenticated-user-id header entirely
  • Update startGoogleOAuth.ts and googleOAuthCallback.ts to use APIGatewayProxyEventV2WithJWTAuthorizer event type throughout
  • Add 4 unit tests for JwtAuthenticatedAppUserProvider covering: valid sub, missing sub, non-string sub, and empty string sub
  • Update startGoogleOAuth.test.ts event fixture to use JWT requestContext shape

Test results

Test Files  13 passed (13)
     Tests  41 passed (41)

pnpm exec tsc --noEmit passes clean.

Closes LEY-15

ltyu added 2 commits March 18, 2026 15:45
- Add JwtClaims type to types.ts for the Auth0 JWT authorizer context shape
- Add JwtAuthenticatedAppUserProvider that reads userId from
  event.requestContext.authorizer.jwt.claims.sub (verified by API Gateway)
- Remove HeaderAuthenticatedAppUserProvider and the unsafe x-authenticated-user-id header
- Update startGoogleOAuth and googleOAuthCallback handlers to use
  APIGatewayProxyEventV2WithJWTAuthorizer event type
- Add unit tests covering valid sub, missing sub, non-string sub, and empty sub cases
- Update startGoogleOAuth.test.ts event fixture to use JWT requestContext shape

Closes LEY-15
The header-based provider is fully replaced by JwtAuthenticatedAppUserProvider.
No remaining imports or references.
@ltyu ltyu merged commit 6d72ff2 into master Mar 18, 2026
1 check passed
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.

1 participant