1
1
import { useEffect , useRef } from "react" ;
2
- import { InspectorOAuthClientProvider } from "../lib/auth" ;
3
2
import { SESSION_KEYS } from "../lib/constants" ;
4
- import { auth } from "@modelcontextprotocol/sdk/client/auth.js" ;
5
3
import { useToast } from "@/hooks/use-toast.ts" ;
6
4
import {
7
5
generateOAuthErrorDescription ,
@@ -39,38 +37,20 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
39
37
}
40
38
41
39
const serverUrl = sessionStorage . getItem ( SESSION_KEYS . SERVER_URL ) ;
40
+
41
+ // ServerURL isn't set, this can happen if we've opened the
42
+ // authentication request in a new tab, so we don't have the same
43
+ // session storage
42
44
if ( ! serverUrl ) {
43
- return notifyError ( "Missing Server URL [DEBUG]" ) ;
45
+ return ;
44
46
}
45
47
46
- onConnect ( serverUrl ) ;
47
-
48
48
if ( ! params . code ) {
49
49
return notifyError ( "Missing authorization code" ) ;
50
50
}
51
51
52
52
sessionStorage . setItem ( SESSION_KEYS . DEBUG_CODE , params . code ) ;
53
53
54
- // let result;
55
- // try {
56
- // // Create an auth provider with the current server URL
57
- // const serverAuthProvider = new InspectorOAuthClientProvider(serverUrl);
58
-
59
- // result = await auth(serverAuthProvider, {
60
- // serverUrl,
61
- // authorizationCode: params.code,
62
- // });
63
- // } catch (error) {
64
- // console.error("OAuth callback error:", error);
65
- // return notifyError(`Unexpected error occurred: ${error}`);
66
- // }
67
-
68
- // if (result !== "AUTHORIZED") {
69
- // return notifyError(
70
- // `Expected to be authorized after providing auth code, got: ${result}`,
71
- // );
72
- // }
73
-
74
54
// Finally, trigger auto-connect
75
55
toast ( {
76
56
title : "Success" ,
@@ -81,22 +61,30 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
81
61
} ;
82
62
83
63
handleCallback ( ) . finally ( ( ) => {
84
- // Only redirect if we have the URL set, otherwise assume it was in a new tab.
64
+ // Only redirect if we have the URL set, otherwise assume this was
65
+ // in a new tab
85
66
if ( sessionStorage . getItem ( SESSION_KEYS . SERVER_URL ) ) {
86
67
window . history . replaceState ( { } , document . title , "/" ) ;
87
68
}
88
69
} ) ;
89
70
} , [ toast , onConnect ] ) ;
90
71
72
+ const callbackParams = parseOAuthCallbackParams ( window . location . search ) ;
73
+
91
74
return (
92
75
< div className = "flex items-center justify-center h-screen" >
93
76
< div className = "mt-4 p-4 bg-secondary rounded-md max-w-md" >
94
77
< p className = "mb-2 text-sm" >
95
78
Please copy this authorization code and return to the Auth Debugger:
96
79
</ p >
97
80
< code className = "block p-2 bg-muted rounded-sm overflow-x-auto text-xs" >
98
- { parseOAuthCallbackParams ( window . location . search ) . code ||
99
- "No code found" }
81
+ { callbackParams . successful
82
+ ? (
83
+ callbackParams as {
84
+ code : string ;
85
+ }
86
+ ) . code
87
+ : `No code found: ${ callbackParams . error } , ${ callbackParams . error_description } ` }
100
88
</ code >
101
89
< p className = "mt-4 text-xs text-muted-foreground" >
102
90
Close this tab and paste the code in the OAuth flow to complete
0 commit comments