switch to metadata from state
This commit is contained in:
parent
20e961ce5c
commit
35eab580ef
2 changed files with 21 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { useCallback, useMemo } from "react";
|
import { useCallback, useMemo, useEffect } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { DebugInspectorOAuthClientProvider } from "../lib/auth";
|
import { DebugInspectorOAuthClientProvider } from "../lib/auth";
|
||||||
import { AlertCircle } from "lucide-react";
|
import { AlertCircle } from "lucide-react";
|
||||||
|
|
@ -60,6 +60,23 @@ const AuthDebugger = ({
|
||||||
authState,
|
authState,
|
||||||
updateAuthState,
|
updateAuthState,
|
||||||
}: AuthDebuggerProps) => {
|
}: AuthDebuggerProps) => {
|
||||||
|
// Initialize loading state
|
||||||
|
useEffect(() => {
|
||||||
|
if (authState.loading && serverUrl) {
|
||||||
|
// Check if we have existing tokens
|
||||||
|
const checkTokens = async () => {
|
||||||
|
const provider = new DebugInspectorOAuthClientProvider(serverUrl);
|
||||||
|
const existingTokens = await provider.tokens();
|
||||||
|
|
||||||
|
updateAuthState({
|
||||||
|
loading: false,
|
||||||
|
oauthTokens: existingTokens || null,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
checkTokens();
|
||||||
|
}
|
||||||
|
}, [serverUrl, authState.loading, updateAuthState]);
|
||||||
const startOAuthFlow = useCallback(() => {
|
const startOAuthFlow = useCallback(() => {
|
||||||
if (!serverUrl) {
|
if (!serverUrl) {
|
||||||
updateAuthState({
|
updateAuthState({
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ export const OAuthFlowProgress = ({
|
||||||
label="Metadata Discovery"
|
label="Metadata Discovery"
|
||||||
{...getStepProps("metadata_discovery")}
|
{...getStepProps("metadata_discovery")}
|
||||||
>
|
>
|
||||||
{provider.getServerMetadata() && (
|
{authState.oauthMetadata && (
|
||||||
<details className="text-xs mt-2">
|
<details className="text-xs mt-2">
|
||||||
<summary className="cursor-pointer text-muted-foreground font-medium">
|
<summary className="cursor-pointer text-muted-foreground font-medium">
|
||||||
OAuth Metadata Sources
|
OAuth Metadata Sources
|
||||||
|
|
@ -165,14 +165,14 @@ export const OAuthFlowProgress = ({
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{provider.getServerMetadata() && (
|
{authState.oauthMetadata && (
|
||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
<p className="font-medium">Authorization Server Metadata:</p>
|
<p className="font-medium">Authorization Server Metadata:</p>
|
||||||
{authState.authServerUrl && <p className="text-xs text-muted-foreground">
|
{authState.authServerUrl && <p className="text-xs text-muted-foreground">
|
||||||
From {new URL('/.well-known/oauth-authorization-server', authState.authServerUrl).href}
|
From {new URL('/.well-known/oauth-authorization-server', authState.authServerUrl).href}
|
||||||
</p>}
|
</p>}
|
||||||
<pre className="mt-2 p-2 bg-muted rounded-md overflow-auto max-h-[300px]">
|
<pre className="mt-2 p-2 bg-muted rounded-md overflow-auto max-h-[300px]">
|
||||||
{JSON.stringify(provider.getServerMetadata(), null, 2)}
|
{JSON.stringify(authState.oauthMetadata, null, 2)}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue