2023-03-15 07:50:03 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
|
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
|
|
|
2023-07-11 07:41:21 +00:00
|
|
|
import { encodeOAuthState } from "../../_utils/encodeOAuthState";
|
2023-03-15 07:50:03 +00:00
|
|
|
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
|
|
|
|
|
|
|
let client_id = "";
|
|
|
|
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
|
|
const appKeys = await getAppKeysFromSlug("zohocrm");
|
|
|
|
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
|
|
|
|
if (!client_id) return res.status(400).json({ message: "zohocrm client id missing." });
|
2023-07-11 07:41:21 +00:00
|
|
|
const state = encodeOAuthState(req);
|
2023-03-15 07:50:03 +00:00
|
|
|
|
|
|
|
const redirectUri = WEBAPP_URL + "/api/integrations/zohocrm/callback";
|
2023-07-11 07:41:21 +00:00
|
|
|
const url = `https://accounts.zoho.com/oauth/v2/auth?scope=ZohoCRM.modules.ALL,ZohoCRM.users.READ,AaaServer.profile.READ&client_id=${client_id}&response_type=code&access_type=offline&redirect_uri=${redirectUri}&state=${state}`;
|
2023-03-15 07:50:03 +00:00
|
|
|
res.status(200).json({ url });
|
|
|
|
}
|