MCPcopy Index your code
hub / github.com/CapSoftware/Cap / exchangeGoogleDriveCode

Function exchangeGoogleDriveCode

packages/web-backend/src/Storage/GoogleDrive.ts:178–206  ·  view source on GitHub ↗
(code: string)

Source from the content-addressed store, hash-verified

176};
177
178export 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
208const fetchGoogleDriveAccessToken = async (
209 config: GoogleDriveIntegrationConfig,

Callers 1

storage.tsFile · 0.90

Calls 3

serverEnvFunction · 0.90
assertDriveResponseFunction · 0.85
fetchFunction · 0.50

Tested by

no test coverage detected