Repository navigation
refactor(auth): split oauth.py into cohesive modules (#122) - #132
Merged
manish-wekan merged 1 commit intoNov 9, 2026
Merged
Conversation
… modules (nitrocloudofficial#122) oauth.py was 516 lines. It is now a 280-line facade that keeps OAuthService, OAuthModule and the fail-open warning, and delegates to: - oauth_types: is_oauth_required, generate_www_authenticate_header, _has_secret - oauth_cache: token-result cache get/set - oauth_tokens: JWKS verification, RFC 7662 introspection, audience check - oauth_discovery: the background metadata / registration HTTP server Dependencies run one way (types <- cache/tokens, oauth_module <- discovery, all <- oauth), with no import cycles. Every name oauth.py defined or imported is still importable from it, and OAuthService keeps the same methods and signatures. No behavior change.
AadarshM07
approved these changes
Nov 8, 2026
Collaborator
There was a problem hiding this comment.
Looks good to me!
Clean refactor following the related issue. All new modules are well under 500 lines with strictly unidirectional dependencies and no import cycles. All auth tests pass, and existing imports, delegation shims, and monkeypatch compatibility are preserved.
Optional changes that does not directly affect merge: TokenInfo in oauth.py line 12 is unused and triggers an F401 linter warning.
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.
Fixes #122.
What changed
nitrostack/auth/oauth.py(516 lines) is split by responsibility.oauth.pyis now a 280-line facade that keepsOAuthService,OAuthModuleand the fail-open warning, and delegates the work:oauth_types.pyTokenInfo,is_oauth_required,generate_www_authenticate_header,_has_secretoauth_cache.pytime.monotonic)oauth_tokens.pyoauth_discovery.pyoauth.pyOAuthService,OAuthModule,warn_if_oauth_fail_openDependencies (one-directional, no cycles)
oauth_types→secretonlyoauth_cache→oauth_typesoauth_tokens→oauth_types,secretoauth_discovery→oauth_module,cimdoauth→ all of the aboveoauth_tokensandoauth_discoveryrefer toOAuthServiceonly underTYPE_CHECKING. Each module imports cleanly on its own in a fresh interpreter.Behavior and imports preserved
oauth.pydefined is still importable from it. The incidental imports callers might use (build_*,apply_cimd_to_registration_body,is_client_registration_enabled,Cimd*Error,unwrap_secret,urllib) are re-exported.OAuthServicehas the same methods with the same signatures. Its private methods (_introspect_via_endpoint,_validate_audience,_cache_get, ...) stay as thin delegates, so existing patches and tests on them keep working._oauth_fail_open_warnedstays inoauth.py.self→service. I diffed the discovery server body to confirm.Checks
developon my machine:test_oauth_client.py::test_all_waiters_can_cancel...(Python 3.14 asyncio) and the code-mode / wheel-build template tests (nosetuptoolsin my venv). CI runs 3.10 to 3.12.oauth.pydrops out of its baseline, since it is now under 500 lines.