File tree Expand file tree Collapse file tree 4 files changed +14
-5
lines changed
Expand file tree Collapse file tree 4 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 11import { useEffect } from 'react' ;
22import { handleOAuthCallback } from '../lib/auth' ;
3+ import { SESSION_KEYS } from '../lib/constants' ;
34
45const OAuthCallback = ( ) => {
56 useEffect ( ( ) => {
67 const handleCallback = async ( ) => {
78 const params = new URLSearchParams ( window . location . search ) ;
89 const code = params . get ( 'code' ) ;
9- const serverUrl = sessionStorage . getItem ( 'mcp_server_url' ) ;
10+ const serverUrl = sessionStorage . getItem ( SESSION_KEYS . SERVER_URL ) ;
1011
1112 if ( ! code || ! serverUrl ) {
1213 console . error ( 'Missing code or server URL' ) ;
@@ -17,7 +18,7 @@ const OAuthCallback = () => {
1718 try {
1819 const accessToken = await handleOAuthCallback ( serverUrl , code ) ;
1920 // Store the access token for future use
20- sessionStorage . setItem ( 'mcp_access_token' , accessToken ) ;
21+ sessionStorage . setItem ( SESSION_KEYS . ACCESS_TOKEN , accessToken ) ;
2122 // Redirect back to the main app
2223 window . location . href = '/' ;
2324 } catch ( error ) {
Original file line number Diff line number Diff line change 11import pkceChallenge from 'pkce-challenge' ;
2+ import { SESSION_KEYS } from './constants' ;
23
34export interface OAuthMetadata {
45 authorization_endpoint : string ;
@@ -36,7 +37,7 @@ export async function startOAuthFlow(serverUrl: string): Promise<string> {
3637 const codeChallenge = challenge . code_challenge ;
3738
3839 // Store code verifier for later use
39- sessionStorage . setItem ( 'mcp_code_verifier' , codeVerifier ) ;
40+ sessionStorage . setItem ( SESSION_KEYS . CODE_VERIFIER , codeVerifier ) ;
4041
4142 // Discover OAuth endpoints
4243 const metadata = await discoverOAuthMetadata ( serverUrl ) ;
@@ -53,7 +54,7 @@ export async function startOAuthFlow(serverUrl: string): Promise<string> {
5354
5455export async function handleOAuthCallback ( serverUrl : string , code : string ) : Promise < string > {
5556 // Get stored code verifier
56- const codeVerifier = sessionStorage . getItem ( 'mcp_code_verifier' ) ;
57+ const codeVerifier = sessionStorage . getItem ( SESSION_KEYS . CODE_VERIFIER ) ;
5758 if ( ! codeVerifier ) {
5859 throw new Error ( 'No code verifier found' ) ;
5960 }
Original file line number Diff line number Diff line change 1+ // OAuth-related session storage keys
2+ export const SESSION_KEYS = {
3+ CODE_VERIFIER : 'mcp_code_verifier' ,
4+ SERVER_URL : 'mcp_server_url' ,
5+ ACCESS_TOKEN : 'mcp_access_token' ,
6+ } as const ;
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { useState } from "react";
1414import { toast } from "react-toastify" ;
1515import { z } from "zod" ;
1616import { startOAuthFlow } from "../auth" ;
17+ import { SESSION_KEYS } from "../constants" ;
1718import { Notification , StdErrNotificationSchema } from "../notificationTypes" ;
1819
1920const DEFAULT_REQUEST_TIMEOUT_MSEC = 10000 ;
@@ -167,7 +168,7 @@ export function useConnection({
167168 console . error ( "Failed to connect to MCP server:" , error ) ;
168169 if ( error instanceof SseError && error . code === 401 ) {
169170 // Store the server URL for the callback handler
170- sessionStorage . setItem ( 'mcp_server_url' , sseUrl ) ;
171+ sessionStorage . setItem ( SESSION_KEYS . SERVER_URL , sseUrl ) ;
171172 const redirectUrl = await startOAuthFlow ( sseUrl ) ;
172173 window . location . href = redirectUrl ;
173174 }
You can’t perform that action at this time.
0 commit comments