MCPcopy Create free account
hub / github.com/modelcontextprotocol/inspector / handleCallback

Function handleCallback

client/src/components/OAuthCallback.tsx:20–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18
19 useEffect(() => {
20 const handleCallback = async () => {
21 // Skip if we've already processed this callback
22 if (hasProcessedRef.current) {
23 return;
24 }
25 hasProcessedRef.current = true;
26
27 const notifyError = (description: string) =>
28 void toast({
29 title: "OAuth Authorization Error",
30 description,
31 variant: "destructive",
32 });
33
34 const params = parseOAuthCallbackParams(window.location.search);
35 if (!params.successful) {
36 return notifyError(generateOAuthErrorDescription(params));
37 }
38
39 const serverUrl = sessionStorage.getItem(SESSION_KEYS.SERVER_URL);
40 if (!serverUrl) {
41 return notifyError("Missing Server URL");
42 }
43
44 let result;
45 try {
46 // Create an auth provider with the current server URL
47 const serverAuthProvider = new InspectorOAuthClientProvider(serverUrl);
48
49 result = await auth(serverAuthProvider, {
50 serverUrl,
51 authorizationCode: params.code,
52 });
53 } catch (error) {
54 console.error("OAuth callback error:", error);
55 return notifyError(`Unexpected error occurred: ${error}`);
56 }
57
58 if (result !== "AUTHORIZED") {
59 return notifyError(
60 `Expected to be authorized after providing auth code, got: ${result}`,
61 );
62 }
63
64 // Finally, trigger auto-connect
65 toast({
66 title: "Success",
67 description: "Successfully authenticated with OAuth",
68 variant: "default",
69 });
70 onConnect(serverUrl);
71 };
72
73 handleCallback().finally(() => {
74 window.history.replaceState({}, document.title, "/");

Callers 1

OAuthCallbackFunction · 0.70

Calls 4

parseOAuthCallbackParamsFunction · 0.90
notifyErrorFunction · 0.85
toastFunction · 0.85

Tested by

no test coverage detected