Commit graph inspector/client/src/lib/auth.ts
Author SHA1 Message Date
Cliff Hall
2539711bc0
Revert "Fix: OAuth CORS errors when Connection Type is 'Via Proxy'" 2026-04-09 10:54:52 -04:00
Ahmet Soormally
d898b3e82f
Merge branch 'main' into fix/oauth-cors-proxy-support 2026-04-07 23:13:05 +02:00
Ahmet Soormally
abe1cf9b4f fix: ensure DCR always registers both redirect URIs
The `redirect_uris` getter used `this.redirectUrl`, which is overridden
by `DebugInspectorOAuthClientProvider` to return `/oauth/callback/debug`.
This caused the `Set` deduplication to collapse both URIs into one,
so DCR only registered `/oauth/callback/debug`. The normal connection
flow then sent `/oauth/callback` in the authorize request, which was
never registered — causing spec-compliant OAuth servers to reject it.

Use the base callback URLs directly instead of the polymorphic getter
so both URIs are always registered regardless of which subclass
initiates DCR.

Fixes #930
2026-04-02 15:42:20 +01:00
Ahmet Soormally
b083d4e1a0 feat: add OAuth proxy support to eliminate CORS issues
Add server-side proxy endpoints for OAuth discovery, client registration,
and token exchange to avoid CORS issues when using proxy connection mode.

Server proxy endpoints:
- GET /oauth/resource-metadata - proxies OAuth protected resource metadata
- GET /oauth/metadata - proxies OAuth authorization server metadata
- POST /oauth/register - proxies dynamic client registration
- POST /oauth/token - proxies token exchange

Client changes:
- Construct correct RFC 9728/8414 path-aware well-known URLs client-side
- Route all OAuth discovery through proxy when in proxy connection mode
- Eliminate direct browser fetches that fail with CORS in proxy mode
2026-03-09 13:43:30 +00:00
Ahmet Soormally
2bf0dd1a03
fix: omit scope field in OAuth DCR when undefined and improve error handling (#1003)
fix: OAuth DCR scope field compliance

Omits the scope field entirely when undefined, per RFC 7591. This allows OAuth servers to assign default scopes instead of registering clients with no scopes.

Tested with Keycloak DCR.
2026-01-18 14:22:21 -07:00
Stanislav Deviatykh
eb76696d97 correctly clear scope 2025-10-22 00:09:57 +03:00
Stanislav Deviatykh
c2dbff738e fix: set user specified scope in DCR 2025-10-16 00:50:42 +03:00
cliffhall
eda547ee7b Fix duplicate OAuth redirect URIs
* In auth.ts
  - add getter for redirect_uris which returns redirectUrl and debugRedirectUrl but de-duped
  - included comments that explains the problem and link to issue
  - in clientMetadata getter,
    - replace hardcoded array value with this..redirect_uris, so it will never contain duplicate uris

Fixes #825
2025-10-11 14:35:47 -04:00
Paul Carleton
b72e3c1233
Revert "fix: filter out client_secret when storing OAuth client information"
This reverts commit 36b9acc97e.
2025-09-24 15:12:52 +01:00
Basil Hosmer
70ddef28f2
Fix OAuth redirect URI mismatch in debug flow
Register both normal and debug redirect URIs in client metadata to prevent mismatch errors when using the Auth tab's debug mode versus normal connection flow.
2025-09-12 22:23:32 -04:00
Jenn Newton
650f3090d2
fix: add validation for OAuth redirect URLs
- Create shared validateRedirectUrl utility to centralize URL validation
- Only allow HTTP and HTTPS protocols in OAuth authorization URLs
- Fix three vulnerable redirect paths that bypassed validation:
  - AuthDebugger.tsx: Direct window.location.href redirect
  - OAuthFlowProgress.tsx: window.open() without validation
  - OAuthFlowProgress.tsx: Direct anchor href attribute
- Add comprehensive test coverage for URL validation
- Update existing auth.ts to use shared validation utility

This prevents malicious MCP servers from injecting javascript: or data:
protocol URLs that would execute XSS attacks when users are redirected
to the authorization endpoint.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-20 10:08:20 -03:00
cliffhall
5323d4d8f4 Fix connect button behavior for Oauth by making sure that scope is included in client metadata when client is registered.
- In auth.ts
    - in InspectorOAuthClientProvider constructor
      - add optional scope param
      - set instance var this.scope to scope param
    - in clientMetadata getter
      - add scope param set to this.scope or ""
  - in useConnection.ts
    - in handleAuthError handler
      - move instantiation of serverAuthProvider until after scope has been determined
      - pass scope to InspectorOAuthClientProvider constructor
2025-08-15 18:40:21 -04:00
Bobby Tiernay
74900fca5d
feat: unify OAuth scope discovery between automatic and manual flows
- Add shared discoverScopes function in auth.ts with resource metadata preference
- Update automatic flow (handleAuthError) to use dynamic scope discovery
- Update manual flow (OAuth state machine) to use shared scope discovery logic
- Add comprehensive test suite for discoverScopes function (11 test cases)
- Fix empty array handling to return undefined instead of empty string
- Maintain backward compatibility with existing oauthScope parameter
- All quality gates pass: TypeScript, linting, formatting, and tests

Resolves OAuth scope discovery inconsistency where automatic flow used static
scopes while manual flow used metadata scopes. Both flows now use identical
shared logic with proper resource metadata preference.
2025-08-14 14:02:29 -04:00
Felix Weinberger
36b9acc97e
fix: filter out client_secret when storing OAuth client information 2025-08-14 17:04:38 +01:00
Cliff Hall
b4d1bc71f6
Merge branch 'main' into main 2025-08-12 16:25:42 -04:00
superboy-zjc
d21e51e6ab fix(auth): sanitize authorization URL 2025-08-12 11:26:44 -07:00
Konstantin Konstantinov
60049a5b6c
reorder methods 2025-08-12 00:29:53 +03:00
Konstantin Konstantinov
929b930618
reusable generateOAuthState helper, introduce in InspectorOAuthClientProvider and in oauth-state-machine, add test 2025-08-11 21:24:26 +03:00
Xiao Yijun
ee39d56e6d
chore: fix lint issue 2025-07-21 11:26:27 +08:00
Xiao Yijun
3b3205228f
refactor: remove resource config 2025-07-08 10:21:40 +08:00
Xiao Yijun
b8120d9f85
feat: support manual entry of OAuth client information 2025-07-08 09:41:55 +08:00
Paul Carleton
5e8e78c31d
Add Auth debugger tab (#355)
* wip auth debugger

* cleanup types and validation

* more cleanup

* draft test

* wip clean up some

* rm toasts

* consolidate state management

* prettier

* hoist state up to App

* working with quick and guided

* sort out displaying debugger

* prettier

* cleanup types

* fix tests

* cleanup comment

* prettier

* fixup types in tests

* prettier

* refactor debug to avoid toasting

* callback shuffling

* linting

* types

* rm toast in test

* bump typescript sdk version to 0.11.2 for scope parameter passing

* use proper scope handling

* test scope parameter passing

* move functions and s/sseUrl/serverUrl/

* extract status message into component

* refactor progress and steps into components

* fix test

* rename quick handler

* one less click

* last step complete

* add state machine

* test and types
2025-05-13 19:37:09 +01:00
Maxwell Gerber
1345a50011
lint 2025-04-16 16:25:51 -07:00
Maxwell Gerber
15960f5aa4
refactor: Use new serverspecifickey API 2025-04-16 16:24:49 -07:00
Maxwell Gerber
0dc6df57d6
Merge remote-tracking branch 'theirs/main' into max/disconnect 2025-04-16 16:10:35 -07:00
Glen Maddern
df0b526a41 fix: store auth tokens with server-specific keys
Changes client information and access tokens to use server-specific keys in sessionStorage. This fixes issues where changing the server URL would try to use tokens from a different server.
2025-04-16 10:14:08 +10:00
Maxwell Gerber
6a16e7cd24
fix: Disconnecting should clear oauth state 2025-04-07 15:15:28 -07:00
Jerome
88984c7bc7
Linting 2025-02-23 15:15:28 +00:00
Jerome
19ee9fa86a
Merge remote-tracking branch 'origin/main' into justin/sdk-auth 2025-02-21 15:31:09 +00:00
Jerome
02479d3ea9
Updating imports 2025-02-21 15:03:14 +00:00
Jerome
c3ece186a4
Using urlencoded params for refresh/auth tokens 2025-02-21 14:51:47 +00:00
Justin Spahr-Summers
e9a50adde7
Update OAuth callback code 2025-02-11 17:42:49 +00:00
Justin Spahr-Summers
eb6af47b21
Refactor to use auth from SDK 2025-02-11 16:39:07 +00:00
Allen Zhou
1b13b574f8 Update auth.ts 2025-02-05 12:45:11 -08:00
Allen Zhou
95bbd60a38 Add zod parsing for OAuthMetadataSchema and OAuthTokensSchema 2025-02-05 12:42:09 -08:00
Allen Zhou
96ba6fd531 Convert OAuthMetadata and OAuthTokens to zod 2025-02-05 12:38:26 -08:00
Allen Zhou
8592cf2d07 Run prettier-fix 2025-02-05 11:22:11 -08:00
Allen Zhou
79547143a8 Add refresh token handling if returned from server 2025-02-03 19:53:53 -08:00
Justin Spahr-Summers
0882a3e0e5
Formatting 2025-01-24 15:23:24 +00:00
Justin Spahr-Summers
874320ebe6
Token exchange body needs to be JSON 2025-01-24 13:44:26 +00:00
Justin Spahr-Summers
02cfb47c83
Extract session storage keys into constants 2025-01-24 13:09:58 +00:00
Justin Spahr-Summers
16cb59670c
OAuth callback handler (not yet attached) 2025-01-24 11:37:35 +00:00
Justin Spahr-Summers
1c4ad60354
Redirect into OAuth flow upon receiving 401 2025-01-24 11:34:07 +00:00