@@ -5,9 +5,14 @@ import {
5
5
OAuthTokens ,
6
6
OAuthTokensSchema ,
7
7
} 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
+ }
9
15
10
- class InspectorOAuthClientProvider implements OAuthClientProvider {
11
16
get redirectUrl ( ) {
12
17
return window . location . origin + "/oauth/callback" ;
13
18
}
@@ -24,7 +29,11 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
24
29
}
25
30
26
31
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 ) ;
28
37
if ( ! value ) {
29
38
return undefined ;
30
39
}
@@ -33,14 +42,16 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
33
42
}
34
43
35
44
saveClientInformation ( clientInformation : OAuthClientInformation ) {
36
- sessionStorage . setItem (
45
+ const key = getServerSpecificKey (
37
46
SESSION_KEYS . CLIENT_INFORMATION ,
38
- JSON . stringify ( clientInformation ) ,
47
+ this . serverUrl ,
39
48
) ;
49
+ sessionStorage . setItem ( key , JSON . stringify ( clientInformation ) ) ;
40
50
}
41
51
42
52
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 ) ;
44
55
if ( ! tokens ) {
45
56
return undefined ;
46
57
}
@@ -49,25 +60,32 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
49
60
}
50
61
51
62
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 ) ) ;
53
65
}
54
66
55
67
redirectToAuthorization ( authorizationUrl : URL ) {
56
68
window . location . href = authorizationUrl . href ;
57
69
}
58
70
59
71
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 ) ;
61
77
}
62
78
63
79
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 ) ;
65
85
if ( ! verifier ) {
66
86
throw new Error ( "No code verifier saved for session" ) ;
67
87
}
68
88
69
89
return verifier ;
70
90
}
71
91
}
72
-
73
- export const authProvider = new InspectorOAuthClientProvider ( ) ;
0 commit comments