-
Notifications
You must be signed in to change notification settings - Fork 156
DNM: Refactor auth package structure for better organization #2060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reorganize the authentication and authorization code into a cleaner, more maintainable package structure with better separation of concerns. Key changes: - Extract OIDC discovery into dedicated pkg/auth/oidc package - Split token validation and introspection into pkg/auth/token with provider pattern for different introspection endpoints - Move HTTP middleware to pkg/auth/middleware package - Extract PKCE generation into separate file in oauth package - Consolidate RFC 9728 resource metadata handling - Add backward compatibility layer in pkg/auth/compat.go The refactoring reduces code duplication, improves testability, and maintains full backward compatibility through deprecated type aliases and wrapper functions. Net reduction: 3,394 lines of code (-65% in modified files) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
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 refactors the authentication and authorization code for better organization and maintainability. The refactoring extracts functionality into dedicated packages with cleaner separation of concerns while maintaining full backward compatibility.
- Extracts OIDC discovery into a dedicated
pkg/auth/oidcpackage - Splits token validation into
pkg/auth/tokenwith provider pattern for introspection - Moves HTTP middleware to
pkg/auth/middlewarepackage - Adds backward compatibility layer to maintain existing API
Reviewed Changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/auth/utils_test.go | Removed - functionality moved to token package |
| pkg/auth/utils.go | Removed - functionality moved to token and middleware packages |
| pkg/auth/token_test.go | Removed - functionality moved to token package |
| pkg/auth/token/validator.go | New token validator implementation with provider pattern |
| pkg/auth/token/providers/rfc7662.go | RFC 7662 token introspection provider |
| pkg/auth/token/providers/helpers.go | Helper functions for token providers |
| pkg/auth/token/providers/google.go | Google tokeninfo introspection provider |
| pkg/auth/token/introspection.go | Introspector registry and interfaces |
| pkg/auth/token/claims.go | Claims context utilities |
| pkg/auth/token.go | Removed - functionality moved to token package |
| pkg/auth/oidc/discovery_test.go | Tests for OIDC discovery functionality |
| pkg/auth/oidc/discovery.go | OIDC discovery implementation |
| pkg/auth/oauth/pkce.go | PKCE parameter generation utilities |
| pkg/auth/oauth/oidc_test.go | Removed - tests moved to oidc package |
| pkg/auth/oauth/oidc.go | Backward compatibility wrapper for OIDC |
| pkg/auth/oauth/manual_test.go | Removed - functionality moved |
| pkg/auth/oauth/flow_test.go | Updated to use extracted PKCE functions |
| pkg/auth/oauth/flow.go | Updated to use extracted PKCE functions |
| pkg/auth/oauth/dynamic_registration.go | Minor interface updates |
| pkg/auth/oauth/config.go | Configuration types moved here |
| pkg/auth/middleware_test.go | Removed - functionality moved to middleware package |
| pkg/auth/middleware/local.go | Local user middleware implementation |
| pkg/auth/middleware/handlers.go | Auth info handler implementation |
| pkg/auth/middleware/auth.go | Token validation middleware |
| pkg/auth/discovery/www_authenticate.go | WWW-Authenticate header parsing |
| pkg/auth/discovery/rfc9728.go | RFC 9728 resource metadata handling |
| pkg/auth/discovery/resource_metadata_test.go | Updated imports for new structure |
| pkg/auth/discovery/discovery.go | Removed duplicate functions |
| pkg/auth/compat.go | Backward compatibility layer |
| pkg/auth/anonymous_test.go | Updated imports for new structure |
| pkg/auth/anonymous.go | Updated imports for new structure |
Comments suppressed due to low confidence (1)
pkg/auth/oauth/flow.go:1
- The Flow struct documentation should be updated to mention that PKCE parameters are now generated using the exported GeneratePKCEParams function from the oauth package.
// Package oauth provides OAuth 2.0 and OIDC authentication functionality.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| authInfo := RFC9728AuthInfo{ | ||
| Resource: resourceURL, | ||
| AuthorizationServers: []string{jwksURL}, // Use JWKS URL as the authorization server | ||
| BearerMethodsSupported: []string{"header"}, | ||
| JWKSURI: jwksURL, | ||
| ScopesSupported: supportedScopes, | ||
| } |
Copilot
AI
Oct 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 54 uses jwksURL as the authorization server, but this should typically be the issuer URL, not the JWKS URL. The JWKS URL is for key verification, while the authorization server is the OAuth issuer.
| var parts []string | ||
|
|
||
| // realm (RFC 6750) - this could be the issuer | ||
| parts = append(parts, fmt.Sprintf(`realm="%s"`, escapeQuotes(validator.JWKSURL()))) |
Copilot
AI
Oct 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using JWKS URL as the realm is incorrect. The realm should typically be the issuer or a human-readable identifier, not the JWKS endpoint URL.
| parts = append(parts, fmt.Sprintf(`realm="%s"`, escapeQuotes(validator.JWKSURL()))) | |
| parts = append(parts, fmt.Sprintf(`realm="%s"`, escapeQuotes(validator.Issuer()))) |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2060 +/- ##
==========================================
- Coverage 48.26% 46.41% -1.86%
==========================================
Files 236 247 +11
Lines 29690 29684 -6
==========================================
- Hits 14331 13778 -553
- Misses 14281 14868 +587
+ Partials 1078 1038 -40 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@claude please review this pull request. |
|
Claude finished @JAORMX's task —— View job Authentication Refactoring PR ReviewI've completed a comprehensive review of this authentication refactoring. This is an excellent example of package reorganization that significantly improves code maintainability while preserving backward compatibility. ✅ Strengths1. Excellent Package Organization
2. Backward Compatibility Excellence
3. Code Quality Improvements
4. Security Considerations
|
Reorganize the authentication and authorization code into a cleaner,
more maintainable package structure with better separation of concerns.
Key changes:
provider pattern for different introspection endpoints
The refactoring reduces code duplication, improves testability, and
maintains full backward compatibility through deprecated type aliases
and wrapper functions.
Net reduction: 3,394 lines of code (-65% in modified files)
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com