wip new metadata
This commit is contained in:
parent
befadc0042
commit
00893afc0b
5 changed files with 19 additions and 38 deletions
|
|
@ -125,7 +125,7 @@ const App = () => {
|
|||
isInitiatingAuth: false,
|
||||
oauthTokens: null,
|
||||
loading: true,
|
||||
oauthStep: "resource_metadata_discovery",
|
||||
oauthStep: "metadata_discovery",
|
||||
oauthMetadata: null,
|
||||
resourceMetadata: null,
|
||||
oauthClientInfo: null,
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ const AuthDebugger = ({
|
|||
serverAuthProvider.clear();
|
||||
updateAuthState({
|
||||
oauthTokens: null,
|
||||
oauthStep: "resource_metadata_discovery",
|
||||
oauthStep: "metadata_discovery",
|
||||
latestError: null,
|
||||
oauthClientInfo: null,
|
||||
authorizationCode: "",
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ interface OAuthFlowProgressProps {
|
|||
}
|
||||
|
||||
const steps: Array<OAuthStep> = [
|
||||
"resource_metadata_discovery",
|
||||
"metadata_discovery",
|
||||
"client_registration",
|
||||
"authorization_redirect",
|
||||
|
|
@ -79,16 +80,6 @@ export const OAuthFlowProgress = ({
|
|||
null,
|
||||
);
|
||||
|
||||
const steps: Array<OAuthStep> = [
|
||||
"resource_metadata_discovery",
|
||||
"metadata_discovery",
|
||||
"client_registration",
|
||||
"authorization_redirect",
|
||||
"authorization_code",
|
||||
"token_request",
|
||||
"complete",
|
||||
];
|
||||
|
||||
const currentStepIdx = steps.findIndex((s) => s === authState.oauthStep);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -135,8 +126,8 @@ export const OAuthFlowProgress = ({
|
|||
|
||||
<div className="space-y-3">
|
||||
<OAuthStepDetails
|
||||
label="Resource Metadata Discovery"
|
||||
{...getStepProps("resource_metadata_discovery")}
|
||||
label="Metadata Discovery"
|
||||
{...getStepProps("metadata_discovery")}
|
||||
>
|
||||
{authState.resourceMetadata && (
|
||||
<details className="text-xs mt-2">
|
||||
|
|
@ -148,11 +139,6 @@ export const OAuthFlowProgress = ({
|
|||
</pre>
|
||||
</details>
|
||||
)}
|
||||
</OAuthStepDetails>
|
||||
<OAuthStepDetails
|
||||
label="Metadata Discovery"
|
||||
{...getStepProps("metadata_discovery")}
|
||||
>
|
||||
{provider.getServerMetadata() && (
|
||||
<details className="text-xs mt-2">
|
||||
<summary className="cursor-pointer text-muted-foreground font-medium">
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import {
|
|||
|
||||
// OAuth flow steps
|
||||
export type OAuthStep =
|
||||
| "resource_metadata_discovery"
|
||||
| "metadata_discovery"
|
||||
| "client_registration"
|
||||
| "authorization_redirect"
|
||||
|
|
|
|||
|
|
@ -20,31 +20,26 @@ export interface StateTransition {
|
|||
execute: (context: StateMachineContext) => Promise<void>;
|
||||
}
|
||||
|
||||
const fetchProtectedResourceMetadata = async (serverUrl: string): Promise<object> => {
|
||||
// TODO: use sdk
|
||||
const url = new URL("/.well-known/oauth-protected-resource", serverUrl);
|
||||
const response = await fetch(url);
|
||||
const resourceMetadata = await response.json();
|
||||
|
||||
return resourceMetadata;
|
||||
}
|
||||
|
||||
// State machine transitions
|
||||
export const oauthTransitions: Record<OAuthStep, StateTransition> = {
|
||||
resource_metadata_discovery: {
|
||||
metadata_discovery: {
|
||||
canTransition: async () => true,
|
||||
execute: async (context) => {
|
||||
// TODO: use sdk
|
||||
const url = new URL("/.well-known/oauth-protected-resource", context.serverUrl);
|
||||
const response = await fetch(url);
|
||||
|
||||
const resourceMetadata = await response.json();
|
||||
context.updateState({
|
||||
resourceMetadata: resourceMetadata,
|
||||
oauthStep: "metadata_discovery",
|
||||
});
|
||||
},
|
||||
},
|
||||
try {
|
||||
|
||||
metadata_discovery: {
|
||||
canTransition: async (context) => !!context.state.resourceMetadata,
|
||||
execute: async (context) => {
|
||||
// TODO: use sdk
|
||||
let authServerUrl = context.serverUrl;
|
||||
if (context.state.resourceMetadata?.authorization_servers?.[0]) {
|
||||
authServerUrl = context.state.resourceMetadata.authorization_servers[0];
|
||||
}
|
||||
const resourceMetadata = fetchProtectedResourceMetadata(serverUrl)
|
||||
|
||||
const metadata = await discoverOAuthMetadata(authServerUrl);
|
||||
if (!metadata) {
|
||||
throw new Error("Failed to discover OAuth metadata");
|
||||
|
|
@ -52,6 +47,7 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
|
|||
const parsedMetadata = await OAuthMetadataSchema.parseAsync(metadata);
|
||||
context.provider.saveServerMetadata(parsedMetadata);
|
||||
context.updateState({
|
||||
resourceMetadata,
|
||||
oauthMetadata: parsedMetadata,
|
||||
oauthStep: "client_registration",
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue