* Implement credential sync secret * Create auth middleware for credential syncing * Create GET endpoint * Update swagger comment * Add verifyCredentialSyncEnabled middleware * Fix middleware input * Fix APP_CREDENTIAL_SHARING_ENABLED to return boolean * Add check for admin API key * Add GET method * Middleware require credential sync secret * Return only the credentialId * Update default CALCOM_CREDENTIAL_SYNC_HEADER_NAME value * Add post endpoint * Return credential object for get endpoint * Require a userId in the param * POST add keys to body * Add PATCH endpoint * Add DELETE endpoint * Fix minimumTokenResponseSchema * Add encrypted key * Remove prototype * Add swagger doc comments * Fix parsing and error handling * Add create selectedCalendar and destinationCalendar params
25 lines
771 B
TypeScript
25 lines
771 B
TypeScript
import type { NextMiddleware } from "next-api-middleware";
|
|
|
|
import { APP_CREDENTIAL_SHARING_ENABLED } from "@calcom/lib/constants";
|
|
|
|
export const verifyCredentialSyncEnabled: NextMiddleware = async (req, res, next) => {
|
|
const { isAdmin } = req;
|
|
|
|
if (!isAdmin) {
|
|
return res.status(403).json({ error: "Only admin API keys can access credential syncing endpoints" });
|
|
}
|
|
|
|
if (!APP_CREDENTIAL_SHARING_ENABLED) {
|
|
return res.status(501).json({ error: "Credential syncing is not enabled" });
|
|
}
|
|
|
|
if (
|
|
req.headers[process.env.CALCOM_CREDENTIAL_SYNC_HEADER_NAME || "calcom-credential-sync-secret"] !==
|
|
process.env.CALCOM_CREDENTIAL_SYNC_SECRET
|
|
) {
|
|
return res.status(401).json({ message: "Invalid credential sync secret" });
|
|
}
|
|
|
|
await next();
|
|
};
|