refactor: migrate to RemoteOAuthStorage for web OAuth handling
This commit is contained in:
parent
d6fe2688e2
commit
7bd26c938e
1 changed files with 317 additions and 44 deletions
|
|
@ -86,7 +86,7 @@ import { useServers } from "@inspector/core/react/useServers.js";
|
|||
import { useSettingsDraft } from "@inspector/core/react/useSettingsDraft.js";
|
||||
import { useClientSettingsDraft } from "@inspector/core/react/useClientSettingsDraft.js";
|
||||
import { useEmaIdpLoginState } from "@inspector/core/react/useEmaIdpLoginState.js";
|
||||
import { getBrowserOAuthStorage } from "@inspector/core/auth/browser/index.js";
|
||||
import { getWebRemoteOAuthStorage } from "./lib/remoteOAuthStorage";
|
||||
import { useManagedTools } from "@inspector/core/react/useManagedTools.js";
|
||||
import { useManagedPrompts } from "@inspector/core/react/useManagedPrompts.js";
|
||||
import { useManagedResources } from "@inspector/core/react/useManagedResources.js";
|
||||
|
|
@ -1428,6 +1428,13 @@ function App() {
|
|||
[messages],
|
||||
);
|
||||
|
||||
// Shared OAuth runtime store (oauth.json via /api/storage/oauth). Memoized so
|
||||
// connect, EMA IdP session, and per-server clear share one in-memory view.
|
||||
const webOAuthStorage = useMemo(
|
||||
() => getWebRemoteOAuthStorage(getAuthToken()),
|
||||
[],
|
||||
);
|
||||
|
||||
// Backend-backed session storage used to carry the fetch (Network) log
|
||||
// across the OAuth full-page redirect. The auth handshake's first half —
|
||||
// protected-resource + auth-server discovery and Dynamic Client
|
||||
|
|
@ -2098,9 +2105,10 @@ function App() {
|
|||
// `onToggleConnection` unloaded the previous one), so all React state is
|
||||
// reset and we recover the initiating server from sessionStorage. We wait for
|
||||
// `servers` to hydrate before acting; the ref guard keeps the exchange to a
|
||||
// single run. The persisted PKCE verifier + DCR client info live in
|
||||
// `BrowserOAuthStorage` and survive the redirect, so `completeOAuthFlow`
|
||||
// exchanges the code without needing the original in-memory state machine.
|
||||
// single run. The persisted PKCE verifier + DCR client info live in shared
|
||||
// `RemoteOAuthStorage` (`oauth.json`) and survive the redirect, so
|
||||
// `completeOAuthFlow` exchanges the code without needing the original
|
||||
// in-memory state machine.
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window.location.pathname !== OAUTH_CALLBACK_PATH) return;
|
||||
|
|
@ -3239,10 +3247,9 @@ function App() {
|
|||
|
||||
const clientSettingsModalValue = clientSettingsDraft ?? EMPTY_CLIENT_SETTINGS;
|
||||
|
||||
const emaOAuthStorage = useMemo(() => getBrowserOAuthStorage(), []);
|
||||
const { loginState: emaIdpLoginState, logout: logoutEmaIdp } =
|
||||
useEmaIdpLoginState(
|
||||
emaOAuthStorage,
|
||||
webOAuthStorage,
|
||||
clientSettingsModalValue.emaEnabled
|
||||
? clientSettingsModalValue.issuer
|
||||
: undefined,
|
||||
|
|
@ -3270,6 +3277,7 @@ function App() {
|
|||
config: server.config,
|
||||
inspectorClient: isActive ? inspectorClient : null,
|
||||
isActiveConnection: isActive,
|
||||
oauthStorage: webOAuthStorage,
|
||||
});
|
||||
if (!cleared) return;
|
||||
|
||||
|
|
@ -3295,6 +3303,7 @@ function App() {
|
|||
[
|
||||
activeServerId,
|
||||
inspectorClient,
|
||||
webOAuthStorage,
|
||||
finalizeExplicitDisconnect,
|
||||
clearOAuthResumeOnExplicitDisconnect,
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue