Skip to content

Conversation

@JAORMX
Copy link
Collaborator

@JAORMX JAORMX commented Nov 4, 2025

Summary

Remove GetClaimsFromContext function and migrate all usages to IdentityFromContext pattern following the authentication unification completed in #2437.

Changes

  • Remove GetClaimsFromContext() from pkg/auth/context.go
  • Update all test files to use IdentityFromContext() and access identity.Claims directly when needed
  • Remove dedicated GetClaimsFromContext test functions
  • Remove unused jwt imports from test files

Rationale

GetClaimsFromContext was added as a backward-compatibility helper during the Identity struct unification in #2437. All production code has migrated to using IdentityFromContext directly, with zero production usages remaining. Tests should verify the actual production API contract.

The function's comment even stated: "This is a helper function for backward compatibility with code that expects MapClaims. New code should use IdentityFromContext and access the Claims field directly."

Since all code is now "new code" using IdentityFromContext, the backward compatibility layer is no longer needed.

Impact

  • Removes ~130 lines of code (function + tests)
  • Simplifies the auth API to a single consistent pattern
  • Improves test clarity by testing the actual production contract
  • All tests pass - no functional changes to production code

Production Usage Analysis

Verified that GetClaimsFromContext had zero production usages:

  • pkg/audit/auditor.go uses IdentityFromContext()
  • pkg/authz/cedar.go uses IdentityFromContext()
  • pkg/auth/tokenexchange/middleware.go uses IdentityFromContext()

The only usages were in test files, which have been updated to use the production pattern.

Testing

All tests pass:

go test ./pkg/auth/...
go test ./pkg/audit/...
go test ./pkg/authz/...

Linting clean:

task lint-fix

Remove GetClaimsFromContext function and migrate all usages to
IdentityFromContext pattern following the authentication unification
completed in d32f2bf.

Changes:
- Remove GetClaimsFromContext() from pkg/auth/context.go
- Update all test files to use IdentityFromContext() and access
  identity.Claims directly when needed
- Remove dedicated GetClaimsFromContext test functions
- Remove unused jwt imports from test files

Rationale:
GetClaimsFromContext was added as a backward-compatibility helper during
the Identity struct unification. All production code has migrated to
using IdentityFromContext directly, with zero production usages
remaining. Tests should verify the actual production API contract.

Impact:
- Removes ~130 lines of code (function + tests)
- Simplifies the auth API to a single pattern
- All tests pass with improved clarity

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@JAORMX JAORMX force-pushed the remove-get-claims-from-context branch from 608ba66 to ed3b079 Compare November 4, 2025 06:19
@JAORMX JAORMX merged commit e198060 into main Nov 4, 2025
28 checks passed
@JAORMX JAORMX deleted the remove-get-claims-from-context branch November 4, 2025 09:04
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