From 50ac5f2892aec85ec571bde277627792b18af0ae Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Fri, 7 Oct 2022 13:59:58 -0400 Subject: [PATCH] Fix MS Teams missing refresh token (#4910) --- packages/app-store/office365video/api/add.ts | 2 +- packages/app-store/office365video/api/callback.ts | 2 +- packages/app-store/office365video/lib/VideoApiAdapter.ts | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/app-store/office365video/api/add.ts b/packages/app-store/office365video/api/add.ts index 99a8778ba6..f1a3e622bd 100644 --- a/packages/app-store/office365video/api/add.ts +++ b/packages/app-store/office365video/api/add.ts @@ -6,7 +6,7 @@ import { WEBAPP_URL } from "@calcom/lib/constants"; import { encodeOAuthState } from "../../_utils/encodeOAuthState"; import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug"; -const scopes = ["OnlineMeetings.ReadWrite"]; +const scopes = ["OnlineMeetings.ReadWrite", "offline_access"]; let client_id = ""; diff --git a/packages/app-store/office365video/api/callback.ts b/packages/app-store/office365video/api/callback.ts index 851ba19630..cad0632511 100644 --- a/packages/app-store/office365video/api/callback.ts +++ b/packages/app-store/office365video/api/callback.ts @@ -8,7 +8,7 @@ import { decodeOAuthState } from "../../_utils/decodeOAuthState"; import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug"; import getInstalledAppPath from "../../_utils/getInstalledAppPath"; -const scopes = ["OnlineMeetings.ReadWrite"]; +const scopes = ["OnlineMeetings.ReadWrite", "offline_access"]; let client_id = ""; let client_secret = ""; diff --git a/packages/app-store/office365video/lib/VideoApiAdapter.ts b/packages/app-store/office365video/lib/VideoApiAdapter.ts index b94f3d1514..eb6e7d61d9 100644 --- a/packages/app-store/office365video/lib/VideoApiAdapter.ts +++ b/packages/app-store/office365video/lib/VideoApiAdapter.ts @@ -49,7 +49,6 @@ const o365Auth = async (credential: Credential) => { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ - scope: "User.Read OnlineMeetings.ReadWrite", client_id, refresh_token: refreshToken, grant_type: "refresh_token", @@ -57,6 +56,10 @@ const o365Auth = async (credential: Credential) => { }), }); const responseBody = await handleErrorsJson(response); + if (responseBody.error) { + console.error(responseBody); + throw new HttpError({ statusCode: 500, message: "Error contacting MS Teams" }); + } // set expiry date as offset from current time. responseBody.expiry_date = Math.round(Date.now() + responseBody.expires_in * 1000); delete responseBody.expires_in;