chore: migrate oauth APIs to app router (#19824)

* migrate api/auth/oauth/me

* migrate the rest

* fix

---------

Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
Benny JooandAnik Dhabal Babu authored and GitHub committed 2025-03-10 17:56:53 +01:00
1 parent 4a4bee7140
commit 3ab053bf17
6 files changed
+40 -53

No files matched your search

@@ -8,7 +8,8 @@ export async function validateAccountOrApiKey(req: NextApiRequest, requiredScope
const apiKey = req.query.apiKey as string;
if (!apiKey) {
const authorizedAccount = await isAuthorized(req, requiredScopes);
const token = req.headers.authorization?.split(" ")[1] || "";
const authorizedAccount = await isAuthorized(token, requiredScopes);
if (!authorizedAccount) throw new HttpError({ statusCode: 401, message: "Unauthorized" });
return { account: authorizedAccount, appApiKey: undefined };
}
@@ -1,11 +1,9 @@
import jwt from "jsonwebtoken";
import type { NextApiRequest } from "next";
import prisma from "@calcom/prisma";
import type { OAuthTokenPayload } from "@calcom/types/oauth";
export default async function isAuthorized(req: NextApiRequest, requiredScopes: string[] = []) {
const token = req.headers.authorization?.split(" ")[1] || "";
export default async function isAuthorized(token: string, requiredScopes: string[] = []) {
let decodedToken: OAuthTokenPayload;
try {
decodedToken = jwt.verify(token, process.env.CALENDSO_ENCRYPTION_KEY || "") as OAuthTokenPayload;