|
1 | 1 | import pkceChallenge from "pkce-challenge";
|
2 | 2 | import { SESSION_KEYS } from "./constants";
|
| 3 | +import { z } from "zod"; |
3 | 4 |
|
4 |
| -export interface OAuthMetadata { |
5 |
| - authorization_endpoint: string; |
6 |
| - token_endpoint: string; |
7 |
| -} |
| 5 | +export const OAuthMetadataSchema = z.object({ |
| 6 | + authorization_endpoint: z.string(), |
| 7 | + token_endpoint: z.string() |
| 8 | +}); |
8 | 9 |
|
9 |
| -export interface OAuthTokens { |
10 |
| - access_token: string; |
11 |
| - refresh_token?: string; |
12 |
| - expires_in?: number; |
13 |
| -} |
| 10 | +export type OAuthMetadata = z.infer<typeof OAuthMetadataSchema>; |
| 11 | + |
| 12 | +export const OAuthTokensSchema = z.object({ |
| 13 | + access_token: z.string(), |
| 14 | + refresh_token: z.string().optional(), |
| 15 | + expires_in: z.number().optional() |
| 16 | +}); |
| 17 | + |
| 18 | +export type OAuthTokens = z.infer<typeof OAuthTokensSchema>; |
14 | 19 |
|
15 | 20 | export async function discoverOAuthMetadata(
|
16 | 21 | serverUrl: string,
|
@@ -93,8 +98,7 @@ export async function handleOAuthCallback(
|
93 | 98 | throw new Error("Token exchange failed");
|
94 | 99 | }
|
95 | 100 |
|
96 |
| - const data = await response.json(); |
97 |
| - return data; |
| 101 | + return await response.json(); |
98 | 102 | }
|
99 | 103 |
|
100 | 104 | export async function refreshAccessToken(
|
@@ -122,6 +126,5 @@ export async function refreshAccessToken(
|
122 | 126 | throw new Error("Token refresh failed");
|
123 | 127 | }
|
124 | 128 |
|
125 |
| - const data = await response.json(); |
126 |
| - return data; |
| 129 | + return await response.json(); |
127 | 130 | }
|
0 commit comments