GPT-6.1 Sol · Balanced

oauth-credential-sync-and-app-integration-enhancements-cal-com

cal.com · TypeScript · M · 100–299 lines · 6 files

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
5 of 9
Comments published
9
Comments matching a bug
5
Comments not matching
4
Cost of this PR
$1.352

Published comments (9)

highbugapps/web/pages/api/webhook/app-credential.ts:50

Metadata lookup by directory key rejects valid app slugs — Valid apps such as `google-calendar` and `zoom` are rejected because `appStoreMetadata` uses directory keys `googlecalendar` and `zoomvideo`. Find the entry by its `slug`, or select the app's `dirName` and use it as the key.

highbugpackages/app-store/_utils/oauth/refreshOAuthTokens.ts:8-15

Synchronized OAuth refresh returns a Response instead of token data — Returning a Fetch `Response` from `refreshOAuthTokens` breaks callers expecting `.data` or direct token properties when synchronization is enabled. Decode the response and adapt it to each caller's expected shape, or normalize both branches and update the callers together.

highbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:5-11

Sync token schema strips expiry and provider-specific fields — The computed keys in `minimumTokenResponseSchema` are literal strings, so expiry fields are stripped, breaking consumers such as Zoom's `newTokens.expires_in` calculation. Define `expires_in` and `expiry_date` explicitly and preserve provider-specific fields.

highbugpackages/app-store/googlecalendar/lib/CalendarService.ts:97-100

Safe-parse result is persisted instead of Google credential fields — Persisting the safe-parse wrapper returned by `parseRefreshTokenResponse` prevents `googleCredentialSchema.parse(credential.key)` from loading the credential, even with synchronization disabled. Check `result.success`, throw `result.error` on failure, and persist `result.data` as `key`.

highbugpackages/app-store/zoho-bigin/lib/CalendarService.ts:92-93

Zoho Bigin token refresh uses the credential ID as the user ID — Passing `credentialId` as `calcomUserId` requests tokens for the wrong principal or a nonexistent user. Thread `credential.userId` from `biginAuth` into this call, retaining `credentialId` for database updates.

highbugpackages/app-store/zoomvideo/lib/VideoApiAdapter.ts:92

Zoom token sync uses an unrecognized app slug — An endpoint resolving `appSlug` cannot find this integration because Zoom's metadata and installed credential use `zoom`, not `zoomvideo`; check `packages/app-store/zoomvideo/_metadata.ts`. Pass `zoom` instead of the directory name.

highbugpackages/app-store/salesforce/lib/CalendarService.ts:96-98

Undefined Prisma client breaks Salesforce client initialization — Salesforce client initialization fails because `prisma` is neither imported nor defined in this file. Import the client from `@calcom/prisma` before calling `prisma.credential.update`.

highbugpackages/app-store/salesforce/lib/CalendarService.ts:75-84

Salesforce token refresh bypasses external credential sharing — Credentials managed by an external platform cannot refresh through this direct `fetch` request when credential sharing and `CALCOM_CREDENTIAL_SYNC_ENDPOINT` are enabled. Route the operation through `refreshOAuthTokens` with the Salesforce slug and `credential.userId`.

mediumperformancepackages/app-store/salesforce/lib/CalendarService.ts:75-84

Salesforce client refreshes tokens unconditionally but uses stale credentials — Every Salesforce service construction adds a token request and database update, yet the connection still uses the original `credentialKey` token. Refresh only when required and initialize the connection with the refreshed credentials.

Gold bugs found (5)

mediumminimumTokenResponseSchema uses computed keys from z.string().toString(), which produce a literal key rather than a wildcard, so the sync-mode schema does not validate or keep expiry and other token fields as intended.
highGoogle Calendar persists the safeParse result object instead of its data as the credential key, corrupting the stored credential so later reads fail.
mediumSalesforce getClient now refreshes the OAuth token and writes the credential on every service construction, adding a network round trip and DB write even when the access token is valid.
highThe new Salesforce token refresh uses prisma without importing it, so the code fails type checking and throws a ReferenceError at runtime.
highThe app-credential webhook looks up appStoreMetadata by app.slug, but the map is keyed by dirName, so apps whose slug differs from their directory (e.g. google-calendar) always get a 404 and their credentials cannot be synced.

Gold bugs missed (4)

mediumThe webhook parses the body with zod .parse and decrypts/JSON-parses the keys without error handling, so invalid payloads produce 500 errors instead of 400 responses.
highparseRefreshTokenResponse writes the hardcoded string 'refresh_token' when the refresh response omits a refresh token, so the stored credential gets an invalid refresh token and later refreshes fail.
highSalesforce checks response.statusText !== 'OK' instead of response.ok when refreshing the token, which can misclassify successful responses, and then ignores the refreshed token.
highAfter refreshing the Salesforce token, jsforce.Connection is created with the stale access_token and instance_url instead of the newly refreshed values.