forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Zoho OAuth via Revert
feat: Create Event and associated contacts (existing and non-existing) in Zoho CRM
- Loading branch information
1 parent
dc4a805
commit 1a3cea5
Showing
17 changed files
with
453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
items: | ||
- 1.png | ||
--- | ||
|
||
{DESCRIPTION} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { createDefaultInstallation } from "@calcom/app-store/_utils/installation"; | ||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; | ||
import { HttpError } from "@calcom/lib/http-error"; | ||
|
||
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug"; | ||
import appConfig from "../config.json"; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.method !== "GET") return res.status(405).json({ message: "Method not allowed" }); | ||
const appKeys = await getAppKeysFromSlug(appConfig.slug); | ||
|
||
let client_id = ""; | ||
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id; | ||
if (!client_id) return res.status(400).json({ message: "ZohoCRM client id missing." }); | ||
|
||
// Check that user is authenticated | ||
req.session = await getServerSession({ req, res }); | ||
const { teamId } = req.query; | ||
const user = req.session?.user; | ||
if (!user) { | ||
throw new HttpError({ statusCode: 401, message: "You must be logged in to do this" }); | ||
} | ||
const userId = user.id; | ||
await createDefaultInstallation({ | ||
appType: `${appConfig.slug}_other_calendar`, | ||
user, | ||
slug: appConfig.slug, | ||
key: {}, | ||
teamId: Number(teamId), | ||
}); | ||
const tenantId = teamId ? teamId : userId; | ||
// @TODO check scopes before deployment | ||
const scopes = [ | ||
"ZohoCRM.modules.ALL", | ||
"ZohoCRM.settings.ALL", | ||
"ZohoCRM.users.ALL", | ||
"AaaServer.profile.READ", | ||
]; | ||
|
||
const queryParams = { | ||
scope: scopes.join(","), | ||
client_id, | ||
response_type: "code", | ||
access_type: "offline", | ||
redirect_uri: "http://localhost:3010/oauth-callback/zohocrm", | ||
state: `{%22tenantId%22:%22${tenantId}%22,%22revertPublicToken%22:%22${process.env.REVERT_PUBLIC_TOKEN}%22}`, | ||
}; | ||
|
||
const urlSearchParams = new URLSearchParams(queryParams); | ||
const queryString = urlSearchParams.toString(); | ||
|
||
res.status(200).json({ | ||
url: `https://accounts.zoho.com/oauth/v2/auth?${queryString}`, | ||
newTab: true, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl"; | ||
|
||
import getInstalledAppPath from "../../_utils/getInstalledAppPath"; | ||
import { decodeOAuthState } from "../../_utils/oauth/decodeOAuthState"; | ||
import appConfig from "../config.json"; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (!req.session?.user?.id) { | ||
return res.status(401).json({ message: "You must be logged in to do this" }); | ||
} | ||
|
||
const state = decodeOAuthState(req); | ||
res.redirect( | ||
getSafeRedirectUrl(state?.returnTo) ?? | ||
getInstalledAppPath({ variant: appConfig.variant, slug: appConfig.slug }) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as add } from "./add"; | ||
export { default as callback } from "./callback"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"/*": "Don't modify slug - If required, do it using cli edit command", | ||
"name": "ZohoCRM", | ||
"slug": "zohocrm-revert", | ||
"type": "zohocrm-revert_other_calendar", | ||
"logo": "icon.svg", | ||
"url": "https://revert.dev", | ||
"variant": "other", | ||
"categories": ["crm"], | ||
"publisher": "Revert.dev", | ||
"email": "[email protected]", | ||
"description": "Zoho CRM is a cloud-based application designed to help your salespeople sell smarter and faster by centralizing customer information, logging their interactions with your company, and automating many of the tasks salespeople do every day", | ||
"isTemplate": false, | ||
"__createdUsingCli": true, | ||
"__template": "basic", | ||
"dirName": "zohocrm-revert" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * as api from "./api"; | ||
export * as lib from "./lib"; |
Oops, something went wrong.