* version and verify-booking-token * username route * api/me * logo route * render email in dev * link route * future * nope and geo location * referal link and daily * intercom route and dynamic variables * intercom route and dynamic variables * scim 2.0 and helpscout route * app credentials * api/book events * fix daily import path in tests * fix buildLegacyRequest generation * fix type errors * migrate the /teams/ routes * move cron jobs * fix daily import path in tests * fix buildLegacyRequest generation * fix type errors * migrate the /teams/ routes * move cron jobs * Revert "api/book events" This reverts commit 607a32fb5b754cad090c2d0cbf64a68f990e220e. * mock next server NextResponse to fix daily video * add default responder to teams api * fix search params * uses nextUrl.searchParams instead of new url * uses nextUrl.searchParams instead of new url * remove outdated api config * remove app dir version of inbound dynamic variables * restore pages version of inbound variables * fix missing code from stupid cursor --------- Co-authored-by: Benny Joo <sldisek783@gmail.com>
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { OAuth2Client } from "googleapis-common";
|
|
import type { NextRequest } from "next/server";
|
|
import { NextResponse } from "next/server";
|
|
|
|
import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
|
|
const scopes = [
|
|
"https://www.googleapis.com/auth/admin.directory.user.readonly",
|
|
"https://www.googleapis.com/auth/admin.directory.customer.readonly",
|
|
];
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
// Get appKeys from google-calendar
|
|
const { client_id, client_secret } = await getAppKeysFromSlug("google-calendar");
|
|
|
|
if (!client_id || typeof client_id !== "string")
|
|
return NextResponse.json({ message: "Google client_id missing." }, { status: 400 });
|
|
|
|
if (!client_secret || typeof client_secret !== "string")
|
|
return NextResponse.json({ message: "Google client_secret missing." }, { status: 400 });
|
|
|
|
// Get teamId from query params
|
|
const teamId = request.nextUrl.searchParams.get("teamId");
|
|
|
|
// use different callback to normal calendar connection
|
|
const redirect_uri = `${WEBAPP_URL}/api/teams/googleworkspace/callback`;
|
|
const oAuth2Client = new OAuth2Client(client_id, client_secret, redirect_uri);
|
|
|
|
const authUrl = oAuth2Client.generateAuthUrl({
|
|
access_type: "offline",
|
|
scope: scopes,
|
|
prompt: "consent",
|
|
state: JSON.stringify({ teamId }),
|
|
});
|
|
|
|
return NextResponse.json({ url: authUrl });
|
|
} catch (error) {
|
|
console.error("Error generating Google Workspace auth URL:", error);
|
|
return NextResponse.json(
|
|
{ message: error instanceof Error ? error.message : "An unexpected error occurred" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|