chore: Add credential sync secret when requesting a token (#13907)

* Rename .env variables

* Remove instances of old variable names

* Add credential sync secret to request for new token

* Update invalid secret message

Co-authored-by: Keith Williams <[email protected]>

---------

Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
Joe Au-YeungandKeith Williams authored and GitHub committed 2024-03-04 19:02:48 +00:00
1 parent 7f53db601d
commit 1f845944ac
5 files changed
+25 -13

No files matched your search

@@ -1,13 +1,25 @@
import { APP_CREDENTIAL_SHARING_ENABLED } from "@calcom/lib/constants";
import {
APP_CREDENTIAL_SHARING_ENABLED,
CREDENTIAL_SYNC_SECRET,
CREDENTIAL_SYNC_SECRET_HEADER_NAME,
} from "@calcom/lib/constants";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const refreshOAuthTokens = async (refreshFunction: () => any, appSlug: string, userId: number | null) => {
// Check that app syncing is enabled and that the credential belongs to a user
if (APP_CREDENTIAL_SHARING_ENABLED && process.env.CALCOM_CREDENTIAL_SYNC_ENDPOINT && userId) {
if (
APP_CREDENTIAL_SHARING_ENABLED &&
process.env.CALCOM_CREDENTIAL_SYNC_ENDPOINT &&
CREDENTIAL_SYNC_SECRET &&
userId
) {
// Customize the payload based on what your endpoint requires
// The response should only contain the access token and expiry date
const response = await fetch(process.env.CALCOM_CREDENTIAL_SYNC_ENDPOINT, {
method: "POST",
headers: {
[CREDENTIAL_SYNC_SECRET_HEADER_NAME]: CREDENTIAL_SYNC_SECRET,
},
body: new URLSearchParams({
calcomUserId: userId.toString(),
appSlug,
+4 -2
View File
@@ -106,8 +106,10 @@ export const ORGANIZATION_MIN_SEATS = 30;
export const IS_MAILHOG_ENABLED = process.env.E2E_TEST_MAILHOG_ENABLED === "1";
export const CALCOM_VERSION = process.env.NEXT_PUBLIC_CALCOM_VERSION as string;
export const APP_CREDENTIAL_SHARING_ENABLED =
process.env.CALCOM_WEBHOOK_SECRET && process.env.CALCOM_APP_CREDENTIAL_ENCRYPTION_KEY;
export const CREDENTIAL_SYNC_SECRET = process.env.CALCOM_CREDENTIAL_SYNC_SECRET;
export const CREDENTIAL_SYNC_SECRET_HEADER_NAME =
process.env.CALCOM_CREDENTIAL_SYNC_SECRET_HEADER_NAME || "calcom-credential-sync-secret";
export const APP_CREDENTIAL_SHARING_ENABLED = CREDENTIAL_SYNC_SECRET && CREDENTIAL_SYNC_SECRET_HEADER_NAME;
export const DEFAULT_LIGHT_BRAND_COLOR = "#292929";
export const DEFAULT_DARK_BRAND_COLOR = "#fafafa";