Skip to content

feat: Sync app credentials between Cal.com & self-hosted platforms#11059

Merged
joeauyeung merged 25 commits intomainfrom
feat/sync-app-credentials
Sep 19, 2023
Merged

feat: Sync app credentials between Cal.com & self-hosted platforms#11059
joeauyeung merged 25 commits intomainfrom
feat/sync-app-credentials

Conversation

@joeauyeung
Copy link
Copy Markdown
Contributor

@joeauyeung joeauyeung commented Aug 31, 2023

What does this PR do?

This PR allows self-hosters that have their own app store, to sync their user's 3rd party credentials with their instance of Cal.com. This allows their app store to be the source of truth for apps.

Fixes # (issue)

Requirement/Documentation

  • If there is a requirement document, please, share it here.
  • If there is ab UI/UX design document, please, share it here.

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Set up the required .env variables that were added in the PR
  • Hit the api/webhook/app-credential endpoint with the correct webhook secret and encrypted payload
  • The new credentials should be created in the DB
  • For the affected apps, force a refresh of the tokens. The endpoint they are hitting should simulate what a self-hoster would have made
  • Force a refresh of the tokens but this time do not enable app credential syncing

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

Checklist

  • I haven't added tests that prove my fix is effective or that my feature works
  • I haven't checked if new and existing unit tests pass locally with my changes

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 31, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2023 8:45pm
api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2023 8:45pm
cal-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2023 8:45pm
dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2023 8:45pm
qa 🔄 Building (Inspect) Visit Preview 💬 Add feedback Sep 19, 2023 8:45pm
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Sep 19, 2023 8:45pm
ui ⬜️ Ignored (Inspect) Visit Preview Sep 19, 2023 8:45pm

@github-actions github-actions Bot added the ❗️ .env changes contains changes to env variables label Aug 31, 2023
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 31, 2023

Thank you for following the naming conventions! 🙏

@zomars zomars added the core area: core, team members only label Aug 31, 2023
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 31, 2023

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@deploysentinel
Copy link
Copy Markdown

deploysentinel Bot commented Aug 31, 2023

Current Playwright Test Results Summary

✅ 121 Passing - ⚠️ 2 Flaky

Run may still be in progress, this comment will be updated as current testing workflow or job completes...

(Last updated on 09/19/2023 08:46:01pm UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: 9fde0e9

Started: 09/19/2023 08:44:40pm UTC

⚠️ Flakes

📄   apps/web/playwright/event-types.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Event Types tests user can add multiple organizer address
Retry 1Initial Attempt
1.79% (5) 5 / 279 runs
failed over last 7 days
16.85% (47) 47 / 279 runs
flaked over last 7 days

📄   packages/embeds/embed-core/playwright/tests/action-based.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Popup Tests should be able to reschedule
Retry 1Initial Attempt
1.78% (5) 5 / 281 runs
failed over last 7 days
96.09% (270) 270 / 281 runs
flaked over last 7 days

View Detailed Build Results


Copy link
Copy Markdown
Contributor Author

@joeauyeung joeauyeung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review

Comment thread apps/web/pages/api/webhook/app-credential.ts
Comment on lines +23 to +25
if (req.headers["calcom-webhook-secret"] !== process.env.CALCOM_WEBHOOK_SECRET) {
return res.status(403).json({ message: "Invalid webhook secret" });
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this secret also be used in future webhooks as well? If we add this to the SaSS product then would need UI to generate a secret based on userId.

userId: z.number().int(),
// The dirname of the app under packages/app-store
appDirName: z.string(),
keys: z.record(z.any()),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking each app should have their own keys schema

Comment thread .env.example Outdated
if (!clientId) return res.status(400).json({ message: "Zoho Bigin client_id missing." });

const redirectUri = WEBAPP_URL + `/api/integrations/${appConfig.slug}/callback`;
const redirectUri = WEBAPP_URL + `/api/integrations/zoho-bigin/callback`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change intended?

zomars
zomars previously approved these changes Sep 18, 2023
Copy link
Copy Markdown
Contributor

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major code objections. LGTM. Although we're going to need some help testing all the apps since this touch every calendar app.

Comment thread apps/web/pages/api/webhook/app-credential.ts Outdated
Comment thread apps/web/pages/api/webhook/app-credential.ts Outdated
@joeauyeung
Copy link
Copy Markdown
Contributor Author

No major code objections. LGTM. Although we're going to need some help testing all the apps since this touch every calendar app.

I tested every app this PR touches but I think it's good to get a second pair of eyes on it.

zomars
zomars previously approved these changes Sep 19, 2023
Copy link
Copy Markdown
Contributor

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @joeauyeung

Ship it

Comment on lines -265 to -272
if (!tokenResponse.success) {
console.error(
"Outlook error grabbing new tokens ~ zodError:",
tokenResponse.error,
"MS response:",
responseJson
);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handled in parseRefreshTokenResponse

@zomars
Copy link
Copy Markdown
Contributor

zomars commented Sep 19, 2023

This had to be reverted. It was preventing bookings with gCal (other cals could be affected)

@joeauyeung joeauyeung mentioned this pull request Sep 20, 2023
2 tasks
Copy link
Copy Markdown

@mfeuerstein mfeuerstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review — approved

Reviewed 30 files. 0 high-severity issues found. Verdict: approved.

packages/app-store/_utils/oauth/encodeOAuthState.ts (low)

  • Reviewed packages/app-store/_utils/oauth/encodeOAuthState.ts — looks good

packages/app-store/_utils/oauth/createOAuthAppCredential.ts (low)

  • Reviewed packages/app-store/_utils/oauth/createOAuthAppCredential.ts — looks good

packages/app-store/_utils/oauth/parseRefreshTokenResponse.ts (low)

  • Reviewed packages/app-store/_utils/oauth/parseRefreshTokenResponse.ts — looks good

packages/app-store/_utils/oauth/refreshOAuthTokens.ts (low)

  • Reviewed packages/app-store/_utils/oauth/refreshOAuthTokens.ts — looks good

packages/app-store/googlecalendar/api/add.ts (low)

  • Reviewed packages/app-store/googlecalendar/api/add.ts — looks good

packages/app-store/googlecalendar/lib/CalendarService.ts (low)

  • Reviewed packages/app-store/googlecalendar/lib/CalendarService.ts — looks good

packages/app-store/_utils/oauth/decodeOAuthState.ts (low)

  • Reviewed packages/app-store/_utils/oauth/decodeOAuthState.ts — looks good

packages/app-store/googlecalendar/api/callback.ts (low)

  • Reviewed packages/app-store/googlecalendar/api/callback.ts — looks good

packages/app-store/hubspot/api/add.ts (low)

  • Reviewed packages/app-store/hubspot/api/add.ts — looks good

packages/app-store/hubspot/api/callback.ts (low)

  • Reviewed packages/app-store/hubspot/api/callback.ts — looks good

packages/app-store/hubspot/lib/CalendarService.ts (low)

  • Reviewed packages/app-store/hubspot/lib/CalendarService.ts — looks good

packages/app-store/larkcalendar/api/callback.ts (low)

  • Reviewed packages/app-store/larkcalendar/api/callback.ts — looks good

apps/web/pages/api/webhook/app-credential.ts (low)

  • Reviewed apps/web/pages/api/webhook/app-credential.ts — looks good

.env.example (low)

  • Reviewed .env.example — looks good

packages/app-store/office365calendar/api/add.ts (low)

  • Reviewed packages/app-store/office365calendar/api/add.ts — looks good

packages/app-store/office365calendar/api/callback.ts (low)

  • Reviewed packages/app-store/office365calendar/api/callback.ts — looks good

packages/app-store/larkcalendar/lib/CalendarService.ts (low)

  • Reviewed packages/app-store/larkcalendar/lib/CalendarService.ts — looks good

packages/app-store/office365video/api/callback.ts (low)

  • Reviewed packages/app-store/office365video/api/callback.ts — looks good

packages/app-store/salesforce/api/add.ts (low)

  • Reviewed packages/app-store/salesforce/api/add.ts — looks good

packages/app-store/office365video/api/add.ts (low)

  • Reviewed packages/app-store/office365video/api/add.ts — looks good

packages/app-store/office365video/lib/VideoApiAdapter.ts (low)

  • Reviewed packages/app-store/office365video/lib/VideoApiAdapter.ts — looks good

packages/app-store/office365calendar/lib/CalendarService.ts (low)

  • Reviewed packages/app-store/office365calendar/lib/CalendarService.ts — looks good

packages/app-store/salesforce/api/callback.ts (low)

  • Reviewed packages/app-store/salesforce/api/callback.ts — looks good

packages/app-store/salesforce/lib/CalendarService.ts (low)

  • Reviewed packages/app-store/salesforce/lib/CalendarService.ts — looks good

packages/app-store/larkcalendar/api/add.ts (low)

  • Reviewed packages/app-store/larkcalendar/api/add.ts — looks good

packages/app-store/webex/lib/VideoApiAdapter.ts (low)

  • Reviewed packages/app-store/webex/lib/VideoApiAdapter.ts — looks good

packages/app-store/tandemvideo/api/callback.ts (low)

  • Reviewed packages/app-store/tandemvideo/api/callback.ts — looks good

packages/app-store/stripepayment/api/callback.ts (low)

  • Reviewed packages/app-store/stripepayment/api/callback.ts — looks good

packages/app-store/zoho-bigin/api/add.ts (low)

  • Reviewed packages/app-store/zoho-bigin/api/add.ts — looks good

packages/app-store/webex/api/callback.ts (low)

  • Reviewed packages/app-store/webex/api/callback.ts — looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only ❗️ .env changes contains changes to env variables ✨ feature New feature or request High priority Created by Linear-GitHub Sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants