(code: string)
| 176 | }; |
| 177 | |
| 178 | export const exchangeGoogleDriveCode = (code: string) => |
| 179 | Effect.tryPromise({ |
| 180 | try: async () => { |
| 181 | const env = serverEnv(); |
| 182 | if (!env.GOOGLE_CLIENT_ID || !env.GOOGLE_CLIENT_SECRET) { |
| 183 | throw new Error("Google OAuth is not configured"); |
| 184 | } |
| 185 | |
| 186 | const response = await fetch("https://oauth2.googleapis.com/token", { |
| 187 | method: "POST", |
| 188 | headers: { "Content-Type": "application/x-www-form-urlencoded" }, |
| 189 | body: new URLSearchParams({ |
| 190 | code, |
| 191 | client_id: env.GOOGLE_CLIENT_ID, |
| 192 | client_secret: env.GOOGLE_CLIENT_SECRET, |
| 193 | redirect_uri: `${env.WEB_URL}/api/desktop/storage/google-drive/callback`, |
| 194 | grant_type: "authorization_code", |
| 195 | }), |
| 196 | }); |
| 197 | |
| 198 | await assertDriveResponse(response); |
| 199 | const tokens = await parseDriveJson<GoogleDriveTokenResponse>(response); |
| 200 | if (!tokens.refresh_token) { |
| 201 | throw new Error("Google did not return a refresh token"); |
| 202 | } |
| 203 | return tokens; |
| 204 | }, |
| 205 | catch: (cause) => new Storage.StorageError({ cause }), |
| 206 | }); |
| 207 | |
| 208 | const fetchGoogleDriveAccessToken = async ( |
| 209 | config: GoogleDriveIntegrationConfig, |
no test coverage detected