Prevent refresh_token nulling if the returned refresh token is empty (#7764)

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
pull/7750/head
Alex van Andel 2023-03-16 14:04:30 +00:00 committed by GitHub
parent b20c0df4e8
commit 358aa8be2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 8 deletions

View File

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