@@ -5,9 +5,14 @@ import {
55 OAuthTokens ,
66 OAuthTokensSchema ,
77} from "@modelcontextprotocol/sdk/shared/auth.js" ;
8- import { SESSION_KEYS } from "./constants" ;
8+ import { SESSION_KEYS , getServerSpecificKey } from "./constants" ;
9+
10+ export class InspectorOAuthClientProvider implements OAuthClientProvider {
11+ constructor ( private serverUrl : string ) {
12+ // Save the server URL to session storage
13+ sessionStorage . setItem ( SESSION_KEYS . SERVER_URL , serverUrl ) ;
14+ }
915
10- class InspectorOAuthClientProvider implements OAuthClientProvider {
1116 get redirectUrl ( ) {
1217 return window . location . origin + "/oauth/callback" ;
1318 }
@@ -24,7 +29,11 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
2429 }
2530
2631 async clientInformation ( ) {
27- const value = sessionStorage . getItem ( SESSION_KEYS . CLIENT_INFORMATION ) ;
32+ const key = getServerSpecificKey (
33+ SESSION_KEYS . CLIENT_INFORMATION ,
34+ this . serverUrl ,
35+ ) ;
36+ const value = sessionStorage . getItem ( key ) ;
2837 if ( ! value ) {
2938 return undefined ;
3039 }
@@ -33,14 +42,16 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
3342 }
3443
3544 saveClientInformation ( clientInformation : OAuthClientInformation ) {
36- sessionStorage . setItem (
45+ const key = getServerSpecificKey (
3746 SESSION_KEYS . CLIENT_INFORMATION ,
38- JSON . stringify ( clientInformation ) ,
47+ this . serverUrl ,
3948 ) ;
49+ sessionStorage . setItem ( key , JSON . stringify ( clientInformation ) ) ;
4050 }
4151
4252 async tokens ( ) {
43- const tokens = sessionStorage . getItem ( SESSION_KEYS . TOKENS ) ;
53+ const key = getServerSpecificKey ( SESSION_KEYS . TOKENS , this . serverUrl ) ;
54+ const tokens = sessionStorage . getItem ( key ) ;
4455 if ( ! tokens ) {
4556 return undefined ;
4657 }
@@ -49,25 +60,32 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
4960 }
5061
5162 saveTokens ( tokens : OAuthTokens ) {
52- sessionStorage . setItem ( SESSION_KEYS . TOKENS , JSON . stringify ( tokens ) ) ;
63+ const key = getServerSpecificKey ( SESSION_KEYS . TOKENS , this . serverUrl ) ;
64+ sessionStorage . setItem ( key , JSON . stringify ( tokens ) ) ;
5365 }
5466
5567 redirectToAuthorization ( authorizationUrl : URL ) {
5668 window . location . href = authorizationUrl . href ;
5769 }
5870
5971 saveCodeVerifier ( codeVerifier : string ) {
60- sessionStorage . setItem ( SESSION_KEYS . CODE_VERIFIER , codeVerifier ) ;
72+ const key = getServerSpecificKey (
73+ SESSION_KEYS . CODE_VERIFIER ,
74+ this . serverUrl ,
75+ ) ;
76+ sessionStorage . setItem ( key , codeVerifier ) ;
6177 }
6278
6379 codeVerifier ( ) {
64- const verifier = sessionStorage . getItem ( SESSION_KEYS . CODE_VERIFIER ) ;
80+ const key = getServerSpecificKey (
81+ SESSION_KEYS . CODE_VERIFIER ,
82+ this . serverUrl ,
83+ ) ;
84+ const verifier = sessionStorage . getItem ( key ) ;
6585 if ( ! verifier ) {
6686 throw new Error ( "No code verifier saved for session" ) ;
6787 }
6888
6989 return verifier ;
7090 }
7191}
72-
73- export const authProvider = new InspectorOAuthClientProvider ( ) ;
0 commit comments