Refactor OAuth token persistence and fix Resource/Audience conflation#4447
Refactor OAuth token persistence and fix Resource/Audience conflation#4447aponcedeleonch wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Large PR Detected
This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.
How to unblock this PR:
Add a section to your PR description with the following format:
## Large PR Justification
[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformationAlternative:
Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.
See our Contributing Guidelines for more details.
This review will be automatically dismissed once you add the justification section.
Large PR justification has been provided. Thank you!
|
✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4447 +/- ##
==========================================
+ Coverage 69.60% 69.74% +0.14%
==========================================
Files 490 491 +1
Lines 50269 50324 +55
==========================================
+ Hits 34988 35100 +112
+ Misses 12595 12538 -57
Partials 2686 2686 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
0dc7c05 to
8f5b6a7
Compare
8f5b6a7 to
18e05e5
Compare
Extract TokenPersistenceManager to pkg/auth/remote to eliminate the repeated nil-check + fetch-cached-token + create-token-source pattern shared by three callers. Generalize RegistryOAuthConfig to OAuthConfig in pkg/config, adding a Resource field (RFC 8707) and an injectable configUpdater callback so callers can supply their own persistence logic. Fix a bug where Audience (provider-specific, e.g. Auth0) was passed where Resource (RFC 8707 resource indicator) was expected: Resource now flows to CreateOAuthConfigFromOIDC and Audience is routed into OAuthParams["audience"] for authorization URL parameters. Add field-level doc comments to OAuthConfig clarifying the distinction between Audience and Resource. Fix %w error wrapping in tryRestoreFromCache and tryRestoreFromCachedTokens. Convert configUpdaterFunc from a type alias to a named type. Add unit tests covering: FetchRefreshToken direct paths, the Resource-vs-Audience split in buildOAuthFlowConfig (regression guard), configUpdater callback invocation, endpoint-override logic, wrapWithPersistence persistence callbacks, and resolveClientCredentials priority logic. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
18e05e5 to
b3652de
Compare
Summary
TokenPersistenceManager: Three callers shared an identical pattern — nil-check a secrets provider, fetch a cached refresh token, create anoauth2.TokenSourcefrom it. Extract this intopkg/auth/remote.TokenPersistenceManagerto eliminate the duplication.FetchRefreshTokenis provided separately fromRestoreFromCacheso callers can do the cheap secret lookup before paying the cost of OIDC network discovery.RegistryOAuthConfig→OAuthConfig: Rename and move topkg/configwith a newResourcefield (RFC 8707) and an injectableconfigUpdatercallback, decoupling the token-source frompkg/configinternals so enterprise callers can supply their own persistence logic.Audience(a provider-specific authorization URL parameter, e.g. Auth0) was being passed whereResource(RFC 8707 resource indicator, sent to the token endpoint) was expected.Resourcenow flows toCreateOAuthConfigFromOIDCandAudienceis routed intoOAuthParams["audience"].Type of change
Large PR Justification
Of the 990 lines changed, 813 are test code (82%) and only 177 are production code across 7 files. The production changes cannot be split because:
RegistryOAuthConfig→OAuthConfigrename touches every caller site simultaneously — leaving half the callers on the old type would not compile. The newResourcefield,configUpdatercallback, andTokenPersistenceManagerextraction are consumed by the same call chains, so they must land together.OAuthConfig.Resourcefield introduced by the rename. Shipping the fix without the generalization would require a throwaway intermediate step.buildOAuthFlowConfig,wrapWithPersistence,resolveClientCredentials,configUpdatercallback). Stripping them into a follow-up PR would leave the bug fix unguarded during review.Test plan
TokenPersistenceManager.FetchRefreshToken(all paths)buildOAuthFlowConfigResource-vs-Audience split — critical regression guard ensuringAudiencelands inOAuthParams["audience"]andResourcedoes NOT appear thereconfigUpdatercallback invocationhandler.buildOAuthFlowConfigendpoint-override logichandler.wrapWithPersistencepersistence callbackshandler.resolveClientCredentialspriority logicgo test ./pkg/auth/remote/... ./pkg/registry/auth/... ./pkg/config/...Does this introduce a user-facing change?
No. This is an internal refactoring and bug fix in the OAuth token persistence layer. The Resource/Audience fix corrects incorrect token requests for RFC 8707-compliant servers and Auth0-style providers, but the CLI interface and configuration schema are unchanged.
Generated with Claude Code