Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: With Credential Sync enabled, fix expired google calendar token handling - Refresh wasn't working #14788

Merged
merged 2 commits into from Apr 29, 2024

Conversation

hariombalhara
Copy link
Member

@hariombalhara hariombalhara commented Apr 29, 2024

What does this PR do?

Fixes issue with refreshed access_token not being used when credential sync is enabled.
Note that the issue isn't replicable if the refresh_token is set. You have to delete the refresh_token to be able to replicate the issue(with credential sync enabled)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How should this be tested?

  1. Make sure that credential sync is enabled
  2. Connect Google Calendar
  3. Delete keys.refresh_token from DB
  4. expiry_date Use a past time here so that the token expires
  5. Simply refresh apps/installed/calendar here. On main, auto-refresh won't occur but in this branch it will occur.

Mandatory Tasks

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

Tests

Working for tests in a follow-up PR. Hitting some issues with mocking. Need to figure that out.

Checklist

  • I haven't added tests that prove my fix is effective or that my feature works

Copy link

vercel bot commented Apr 29, 2024

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 Apr 29, 2024 8:24pm
platform-starter-kit ❌ Failed (Inspect) Apr 29, 2024 8:24pm
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Apr 29, 2024 8:24pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Apr 29, 2024 8:24pm

Copy link
Contributor

github-actions bot commented Apr 29, 2024

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link.

Copy link
Member Author

hariombalhara commented Apr 29, 2024

Copy link
Contributor

github-actions bot commented Apr 29, 2024

📦 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! 🙌

Copy link

deploysentinel bot commented Apr 29, 2024

Current Playwright Test Results Summary

✅ 315 Passing - ⚠️ 18 Flaky

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

(Last updated on 04/29/2024 08:36:20pm UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: 36eb5ca

Started: 04/29/2024 08:33:10pm 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 -- legacy user can add multiple organizer address
Retry 1Initial Attempt
0% (0) 0 / 232 runs
failed over last 7 days
1.72% (4) 4 / 232 runs
flaked over last 7 days

📄   packages/embeds/embed-core/playwright/tests/action-based.e2e.ts • 9 Flakes

Top 1 Common Error Messages

null

9 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Popup Tests should open embed iframe on click - Configured with light theme
Retry 1Initial Attempt
15.35% (37) 37 / 241 runs
failed over last 7 days
54.36% (131) 131 / 241 runs
flaked over last 7 days
Popup Tests should be able to reschedule
Retry 1Initial Attempt
-179.45% (-131) -131 / 73 runs
failed over last 7 days
179.45% (131) 131 / 73 runs
flaked over last 7 days
Popup Tests should open Routing Forms embed on click
Retry 1Initial Attempt
-178.08% (-130) -130 / 73 runs
failed over last 7 days
178.08% (130) 130 / 73 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe according to system theme when no theme is configured through Embed API
Retry 1Initial Attempt
-176.71% (-129) -129 / 73 runs
failed over last 7 days
176.71% (129) 129 / 73 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe(Booker Profile Page) with dark theme when configured with dark theme using Embed API
Retry 1Initial Attempt
-176.71% (-129) -129 / 73 runs
failed over last 7 days
176.71% (129) 129 / 73 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe according to system theme when configured with 'auto' theme using Embed API
Retry 1Initial Attempt
-176.71% (-129) -129 / 73 runs
failed over last 7 days
176.71% (129) 129 / 73 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe(Event Booking Page) with dark theme when configured with dark theme using Embed API
Retry 1Initial Attempt
-176.71% (-129) -129 / 73 runs
failed over last 7 days
176.71% (129) 129 / 73 runs
flaked over last 7 days
Popup Tests should open on clicking child element
Retry 1Initial Attempt
-163.64% (-36) -36 / 22 runs
failed over last 7 days
163.64% (36) 36 / 22 runs
flaked over last 7 days
Popup Tests prendered embed should be loaded and apply the config given to it
Retry 1Initial Attempt
-176.71% (-129) -129 / 73 runs
failed over last 7 days
176.71% (129) 129 / 73 runs
flaked over last 7 days

📄   packages/app-store/routing-forms/playwright/tests/basic.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Routing Forms Seeded Routing Form Test preview should return correct route
Retry 1Initial Attempt
0.42% (1) 1 / 239 run
failed over last 7 days
35.98% (86) 86 / 239 runs
flaked over last 7 days

📄   apps/web/playwright/webhook.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
BOOKING_RESCHEDULED when rescheduling to a booking that already exists, should send a booking rescheduled event with the existant booking uid
Retry 1Initial Attempt
10.43% (22) 22 / 211 runs
failed over last 7 days
34.12% (72) 72 / 211 runs
flaked over last 7 days

📄   packages/embeds/embed-core/playwright/tests/namespacing.e2e.ts • 4 Flakes

Top 1 Common Error Messages

null

4 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Namespacing Inline Embed Double install Embed Snippet with inline embed using a namespace
Retry 1Initial Attempt
0% (0) 0 / 228 runs
failed over last 7 days
53.51% (122) 122 / 228 runs
flaked over last 7 days
Namespacing Different namespaces can have different init configs
Retry 1Initial Attempt
0% (0) 0 / 226 runs
failed over last 7 days
53.10% (120) 120 / 226 runs
flaked over last 7 days
Namespacing Inline Embed Double install Embed Snippet with inline embed without a namespace(i.e. default namespace)
Retry 1Initial Attempt
0% (0) 0 / 228 runs
failed over last 7 days
54.39% (124) 124 / 228 runs
flaked over last 7 days
Namespacing Inline Embed Add inline embed using a namespace without reload
Retry 1Initial Attempt
0.44% (1) 1 / 228 run
failed over last 7 days
53.51% (122) 122 / 228 runs
flaked over last 7 days

📄   apps/web/playwright/teams.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Teams - NonOrg -- future Can create a booking for Round Robin EventType
Retry 2Retry 1Initial Attempt
17.60% (44) 44 / 250 runs
failed over last 7 days
22.40% (56) 56 / 250 runs
flaked over last 7 days

📄   apps/web/playwright/integrations-stripe.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Stripe integration Pending payment booking should not be confirmed by default
Retry 1Initial Attempt
1.32% (3) 3 / 227 runs
failed over last 7 days
23.35% (53) 53 / 227 runs
flaked over last 7 days

View Detailed Build Results


@@ -85,13 +85,15 @@ export default class GoogleCalendarService implements Calendar {
this.credential = credential;
this.auth = this.initGoogleAuth(credential);
this.log = log.getSubLogger({ prefix: [`[[lib] ${this.integrationName}`] });
this.credential = credential;
Copy link
Member Author

Choose a reason for hiding this comment

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

It was a duplicate code line(of line 85)

}

private async getMyGoogleAuthSingleton() {
const googleCredentials = OAuth2UniversalSchema.parse(this.credential.key);
if (this.myGoogleAuth) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Simplified the code.

const { client_id, client_secret, redirect_uris } = await getGoogleAppKeys();
this.myGoogleAuth = this.myGoogleAuth || new MyGoogleAuth(client_id, client_secret, redirect_uris[0]);
const googleCredentials = OAuth2UniversalSchema.parse(this.credential.key);
this.myGoogleAuth = new MyGoogleAuth(client_id, client_secret, redirect_uris[0]);
this.myGoogleAuth.setCredentials(googleCredentials);
Copy link
Member Author

Choose a reason for hiding this comment

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

Now setCredentials is also called only the first time. As getMyGoogleAuthSingleton can be called multiple times, we shouldn't set it again and again.

Rest of the code should ensure that setCredentials is called when needed

where: {
id: credential.id,
},
data: {
key: token,
},
});

// Update cached credential as well
this.credential.key = key;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is important line which fixes the issue.

We update the token in DB. But in case of google-calendar there is a cached value here as well. We should keep it upto-date in case someone use this value.

@hariombalhara hariombalhara changed the title Handle changed cred key fix: With Credential Sync enabled, fix expired google calendar token handling - Refresh wasn't working Apr 29, 2024
@hariombalhara hariombalhara marked this pull request as ready for review April 29, 2024 09:36
@graphite-app graphite-app bot requested a review from a team April 29, 2024 09:36
@dosubot dosubot bot added the 🐛 bug Something isn't working label Apr 29, 2024
Copy link

graphite-app bot commented Apr 29, 2024

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (04/29/24)

1 reviewer was added to this PR based on Keith Williams's automation.

Copy link
Contributor

@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.

Tested credential syncing GCal w/o refresh_token it's grabbing the new token and working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working consumer core area: core, team members only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants