resumption working
This commit is contained in:
parent
0dbf75a664
commit
20e961ce5c
1 changed files with 54 additions and 18 deletions
|
|
@ -20,6 +20,7 @@ import {
|
||||||
import { OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
|
import { OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||||
import { SESSION_KEYS, getServerSpecificKey } from "./lib/constants";
|
import { SESSION_KEYS, getServerSpecificKey } from "./lib/constants";
|
||||||
import { AuthDebuggerState, EMPTY_DEBUGGER_STATE } from "./lib/auth-types";
|
import { AuthDebuggerState, EMPTY_DEBUGGER_STATE } from "./lib/auth-types";
|
||||||
|
import { OAuthStateMachine } from "./lib/oauth-state-machine";
|
||||||
import { cacheToolOutputSchemas } from "./utils/schemaUtils";
|
import { cacheToolOutputSchemas } from "./utils/schemaUtils";
|
||||||
import React, {
|
import React, {
|
||||||
Suspense,
|
Suspense,
|
||||||
|
|
@ -231,7 +232,7 @@ const App = () => {
|
||||||
|
|
||||||
// Update OAuth debug state during debug callback
|
// Update OAuth debug state during debug callback
|
||||||
const onOAuthDebugConnect = useCallback(
|
const onOAuthDebugConnect = useCallback(
|
||||||
({
|
async ({
|
||||||
authorizationCode,
|
authorizationCode,
|
||||||
errorMsg,
|
errorMsg,
|
||||||
restoredState,
|
restoredState,
|
||||||
|
|
@ -242,28 +243,63 @@ const App = () => {
|
||||||
}) => {
|
}) => {
|
||||||
setIsAuthDebuggerVisible(true);
|
setIsAuthDebuggerVisible(true);
|
||||||
|
|
||||||
if (restoredState) {
|
if (errorMsg) {
|
||||||
// Restore the previous auth state
|
|
||||||
updateAuthState({
|
updateAuthState({
|
||||||
...restoredState,
|
latestError: new Error(errorMsg),
|
||||||
// Update with the new authorization code if provided
|
|
||||||
authorizationCode: authorizationCode || restoredState.authorizationCode,
|
|
||||||
oauthStep: authorizationCode ? "token_request" : restoredState.oauthStep,
|
|
||||||
latestError: errorMsg ? new Error(errorMsg) : restoredState.latestError,
|
|
||||||
});
|
});
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (restoredState && authorizationCode) {
|
||||||
|
// Restore the previous auth state and continue the OAuth flow
|
||||||
|
let currentState: AuthDebuggerState = {
|
||||||
|
...restoredState,
|
||||||
|
authorizationCode,
|
||||||
|
oauthStep: "token_request",
|
||||||
|
isInitiatingAuth: true,
|
||||||
|
statusMessage: null,
|
||||||
|
latestError: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Create a new state machine instance to continue the flow
|
||||||
|
const stateMachine = new OAuthStateMachine(sseUrl, (updates) => {
|
||||||
|
currentState = { ...currentState, ...updates };
|
||||||
|
});
|
||||||
|
|
||||||
|
// Continue stepping through the OAuth flow from where we left off
|
||||||
|
while (currentState.oauthStep !== "complete" && currentState.oauthStep !== "authorization_code") {
|
||||||
|
await stateMachine.executeStep(currentState);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentState.oauthStep === "complete") {
|
||||||
|
// After the flow completes or reaches a user-input step, update the app state
|
||||||
|
updateAuthState({
|
||||||
|
...currentState,
|
||||||
|
statusMessage: {
|
||||||
|
type: "success",
|
||||||
|
message: "Authentication completed successfully",
|
||||||
|
},
|
||||||
|
isInitiatingAuth: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("OAuth continuation error:", error);
|
||||||
|
updateAuthState({
|
||||||
|
latestError: error instanceof Error ? error : new Error(String(error)),
|
||||||
|
statusMessage: {
|
||||||
|
type: "error",
|
||||||
|
message: `Failed to complete OAuth flow: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
},
|
||||||
|
isInitiatingAuth: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (authorizationCode) {
|
||||||
// Fallback to the original behavior if no state was restored
|
// Fallback to the original behavior if no state was restored
|
||||||
if (authorizationCode) {
|
updateAuthState({
|
||||||
updateAuthState({
|
authorizationCode,
|
||||||
authorizationCode,
|
oauthStep: "token_request",
|
||||||
oauthStep: "token_request",
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
if (errorMsg) {
|
|
||||||
updateAuthState({
|
|
||||||
latestError: new Error(errorMsg),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue