Files
calendar/packages/app-store/nextcloudtalk/api/add.ts
T
de503add83 feat: add nextcloud talk app (#16455)
* Initial draft of nextcloud app

* Add video adapter for creating a new conversation via API

* Make links dynamic, add nc user and pwd for auth, fix link creation

* Add nextcloudTalk app to yarn.lock

* Fix screenshot name

* Add OAuth2 handler

* Fix type for booking reference and fix access token header param, (for creating and deleting a meeting)

* Remove comment

* Add README.md file

* Fix redirect URL for authenticating Nextcloud user

---------

Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com>
Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
2024-10-09 17:52:30 +05:30

37 lines
1.2 KiB
TypeScript

import type { NextApiRequest } from "next";
import { stringify } from "querystring";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
import { encodeOAuthState } from "../../_utils/oauth/encodeOAuthState";
async function handler(req: NextApiRequest) {
const user = req?.session?.user;
if (!user) {
return { status: 401, body: { error: "Unauthorized" } };
}
const appKeys = await getAppKeysFromSlug("nextcloudtalk");
const hostUrl = appKeys.nextcloudTalkHost as string;
const client_id = appKeys.nextcloudTalkClientId as string;
const client_secret = appKeys.nextcloudTalkClientSecret as string;
const state = encodeOAuthState(req);
const params = {
response_type: "code",
client_id,
client_secret,
redirect_uri: `${WEBAPP_URL}/api/integrations/nextcloudtalk/callback`,
state,
};
const query = stringify(params);
const url = `${hostUrl}/index.php/apps/oauth2/authorize?${query}`;
return { url };
}
export default defaultHandler({
GET: Promise.resolve({ default: defaultResponder(handler) }),
});