Skip to content

fix(templates): standardize OAuth conditional loading and fix ScopeGuard bypass - #342

Open
hemantj-cloud wants to merge 1 commit into
mainfrom
fix/oauth-conditional-loading-and-scope-guard
Open

fix(templates): standardize OAuth conditional loading and fix ScopeGuard bypass#342
hemantj-cloud wants to merge 1 commit into
mainfrom
fix/oauth-conditional-loading-and-scope-guard

Conversation

@hemantj-cloud

Copy link
Copy Markdown
Collaborator

Description

This PR standardizes OAuth 2.1 handling in the typescript-oauth template to align with industry standards and the MCP specification:

  1. Conditional OAuthModule Loading:

    • In development (OAUTH_REQUIRED=false), OAuthModule is not loaded, which stops emitting [NITROSTACK_OAUTH] discovery signals and prevents clients (NitroStudio, ChatGPT, Cursor) from opening unwanted browser login popups.
    • When OAUTH_REQUIRED=true, OAuthModule is loaded dynamically and enforces strict token validation.
  2. ScopeGuard Enforcement Gate:

    • Updated createScopeGuard to check if (!OAuthModule.isAuthRequired()) return true;, preventing unauthenticated local requests from failing with Insufficient scope.
  3. Clean Dev Startup:

    • Registered a fallback value for OAuthModule in DI when OAUTH_REQUIRED=false to suppress false-positive container warnings on startup.

Testing

  • Verified clean startup and unauthenticated tool execution when OAUTH_REQUIRED=false.
  • Verified strict enforcement, discovery metadata, and JWKS token verification when OAUTH_REQUIRED=true.
  • All unit tests passing.

…ard bypass

- Conditionally load OAuthModule only when OAUTH_REQUIRED=true to prevent unwanted browser redirects in dev mode
- Fix createScopeGuard to bypass scope validation when !OAuthModule.isAuthRequired()
- Suppress unconfigured OAuthModule DI warning in index.ts for clean development startup
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.

1 participant