Skip to content

refactor(auth): split oauth.py into cohesive modules (#122) - #132

Merged
manish-wekan merged 1 commit into
nitrocloudofficial:developfrom
ROHIT-JR:refactor/122-split-oauth
Nov 9, 2026
Merged

manish-wekan merged 1 commit into
nitrocloudofficial:developfrom
ROHIT-JR:refactor/122-split-oauth

Conversation

@ROHIT-JR

@ROHIT-JR ROHIT-JR commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Fixes #122.

What changed

nitrostack/auth/oauth.py (516 lines) is split by responsibility. oauth.py is now a 280-line facade that keeps OAuthService, OAuthModule and the fail-open warning, and delegates the work:

Module Lines Contents
oauth_types.py 44 TokenInfo, is_oauth_required, generate_www_authenticate_header, _has_secret
oauth_cache.py 26 token-result cache get/set (TTL on time.monotonic)
oauth_tokens.py 121 JWKS verification, RFC 7662 introspection, RFC 8707 audience check, JWKS client cache
oauth_discovery.py 165 background metadata / client-registration HTTP server
oauth.py 280 facade: OAuthService, OAuthModule, warn_if_oauth_fail_open

Dependencies (one-directional, no cycles)

  • oauth_types → secret only
  • oauth_cache → oauth_types
  • oauth_tokens → oauth_types, secret
  • oauth_discovery → oauth_module, cimd
  • oauth → all of the above

oauth_tokens and oauth_discovery refer to OAuthService only under TYPE_CHECKING. Each module imports cleanly on its own in a fresh interpreter.

Behavior and imports preserved

  • Every name oauth.py defined 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.
  • OAuthService has 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_warned stays in oauth.py.
  • The moved code is unchanged apart from self → service. I diffed the discovery server body to confirm.

Checks

  • No test changes. The OAuth, auth, secret and transport tests all pass unchanged.
  • Full suite locally: 1321 passed. The 3 failures and 2 errors are the same on unmodified develop on my machine: test_oauth_client.py::test_all_waiters_can_cancel... (Python 3.14 asyncio) and the code-mode / wheel-build template tests (no setuptools in my venv). CI runs 3.10 to 3.12.
  • The file-length check from ci: enforce 500-line Python file-length ratchet (#111) #126 passes. oauth.py drops out of its baseline, since it is now under 500 lines.

… 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.
@ROHIT-JR
ROHIT-JR requested a review from AadarshM07 November 7, 2026 14:44

@AadarshM07 AadarshM07 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@manish-wekan
manish-wekan merged commit e9e81ba into nitrocloudofficial:develop Nov 9, 2026
3 checks 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.

3 participants