Convert OAuthMetadata and OAuthTokens to zod
This commit is contained in:
@@ -1,16 +1,21 @@
|
|||||||
import pkceChallenge from "pkce-challenge";
|
import pkceChallenge from "pkce-challenge";
|
||||||
import { SESSION_KEYS } from "./constants";
|
import { SESSION_KEYS } from "./constants";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
export interface OAuthMetadata {
|
export const OAuthMetadataSchema = z.object({
|
||||||
authorization_endpoint: string;
|
authorization_endpoint: z.string(),
|
||||||
token_endpoint: string;
|
token_endpoint: z.string()
|
||||||
}
|
});
|
||||||
|
|
||||||
export interface OAuthTokens {
|
export type OAuthMetadata = z.infer<typeof OAuthMetadataSchema>;
|
||||||
access_token: string;
|
|
||||||
refresh_token?: string;
|
export const OAuthTokensSchema = z.object({
|
||||||
expires_in?: number;
|
access_token: z.string(),
|
||||||
}
|
refresh_token: z.string().optional(),
|
||||||
|
expires_in: z.number().optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
export type OAuthTokens = z.infer<typeof OAuthTokensSchema>;
|
||||||
|
|
||||||
export async function discoverOAuthMetadata(
|
export async function discoverOAuthMetadata(
|
||||||
serverUrl: string,
|
serverUrl: string,
|
||||||
@@ -93,8 +98,7 @@ export async function handleOAuthCallback(
|
|||||||
throw new Error("Token exchange failed");
|
throw new Error("Token exchange failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
return await response.json();
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function refreshAccessToken(
|
export async function refreshAccessToken(
|
||||||
@@ -122,6 +126,5 @@ export async function refreshAccessToken(
|
|||||||
throw new Error("Token refresh failed");
|
throw new Error("Token refresh failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
return await response.json();
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user