-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
private async getMyGoogleAuthSingleton() { | ||
const googleCredentials = OAuth2UniversalSchema.parse(this.credential.key); | ||
if (this.myGoogleAuth) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplified the code. |
||
return this.myGoogleAuth; | ||
} | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now Rest of the code should ensure that |
||
return this.myGoogleAuth; | ||
} | ||
|
@@ -151,14 +153,18 @@ export default class GoogleCalendarService implements Calendar { | |
}, | ||
updateTokenObject: async (token) => { | ||
this.myGoogleAuth.setCredentials(token); | ||
await prisma.credential.update({ | ||
|
||
const { key } = await prisma.credential.update({ | ||
where: { | ||
id: credential.id, | ||
}, | ||
data: { | ||
key: token, | ||
}, | ||
}); | ||
|
||
// Update cached credential as well | ||
this.credential.key = key; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
}, | ||
}); | ||
this.oAuthManagerInstance = auth; | ||
|
There was a problem hiding this comment.
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)