Scheduling infrastructure for absolutely everyone.
Prevent refresh_token nulling if the returned refresh token is empty (#7764)
Alex van Andel358aa8be2bb6
diff --git a/packages/app-store/office365calendar/lib/CalendarService.ts b/packages/app-store/office365calendar/lib/CalendarService.tsindex 63bfee84d35..a15da00f1d4 100644--- a/packages/app-store/office365calendar/lib/CalendarService.ts+++ b/packages/app-store/office365calendar/lib/CalendarService.ts@@ -1,4 +1,5 @@import type { Calendar as OfficeCalendar, User } from "@microsoft/microsoft-graph-types-beta";+import { z } from "zod";import dayjs from "@calcom/dayjs";import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";@@ -38,6 +39,14 @@ interface IBatchResponse {responses: ISettledResponse[];}+const refreshTokenResponseSchema = z.object({+ access_token: z.string(),+ expires_in: z+ .number()+ .transform((currentTimeOffsetInSeconds) => Math.round(+new Date() / 1000 + currentTimeOffsetInSeconds)),+ refresh_token: z.string().optional(),+});+export default class Office365CalendarService implements Calendar {private url = "";private integrationName = "";@@ -217,14 +226,7 @@ export default class Office365CalendarService implements Calendar {client_secret,}),});- const responseBody = await handleErrorsJson<{- access_token: string;- expires_in: number;- refresh_token: string;- }>(response);- o365AuthCredentials.access_token = responseBody.access_token;- o365AuthCredentials.refresh_token = responseBody.refresh_token;- o365AuthCredentials.expiry_date = Math.round(+new Date() / 1000 + responseBody.expires_in);+ const o365AuthCredentials = refreshTokenResponseSchema.parse(await handleErrorsJson(response));await prisma.credential.update({where: {id: credential.id,