only approve zapier api key

pr/2623
CarinaWolli 2022-04-26 13:21:03 +02:00
parent 0f25d31361
commit 831c85dfef
4 changed files with 24 additions and 16 deletions

View File

@ -4,6 +4,7 @@ import { v4 } from "uuid";
import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
import prisma from "@calcom/prisma";
import { ApiKeyType } from "@prisma/client";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const apiKey = req.query.apiKey as string;
@ -12,7 +13,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.status(401).json({ message: "No API key provided" });
}
const validKey = await findValidApiKey(apiKey);
const validKey = await findValidApiKey(apiKey, ApiKeyType.ZAPIER);
if (!validKey) {
return res.status(401).json({ message: "API key not valid" });

View File

@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
import prisma from "@calcom/prisma";
import { ApiKeyType } from "@prisma/client";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const apiKey = req.query.apiKey as string;
@ -10,7 +11,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.status(401).json({ message: "No API key provided" });
}
const validKey = await findValidApiKey(apiKey);
const validKey = await findValidApiKey(apiKey, ApiKeyType.ZAPIER);
if (!validKey) {
return res.status(401).json({ message: "API not valid" });

View File

@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
import prisma from "@calcom/prisma";
import { ApiKeyType } from "@prisma/client";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const apiKey = req.query.apiKey as string;
@ -10,7 +11,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.status(401).json({ message: "No API key provided" });
}
const validKey = await findValidApiKey(apiKey);
const validKey = await findValidApiKey(apiKey, ApiKeyType.ZAPIER);
if (!validKey) {
return res.status(401).json({ message: "API not valid" });

View File

@ -1,22 +1,27 @@
import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys";
import prisma from "@calcom/prisma";
import { ApiKeyType } from "@prisma/client";
const findValidApiKey = async (apiKey: string) => {
const findValidApiKey = async (apiKey: string, apiKeyType: ApiKeyType) => {
const hashedKey = hashAPIKey(apiKey.substring(process.env.API_KEY_PREFIX?.length || 0));
const validKey = await prisma.apiKey.findFirst({
where: {
AND: [
{
hashedKey,
},
{
expiresAt: {
gte: new Date(Date.now()),
where: {
AND: [
{
hashedKey,
},
},
],
},
});
{
expiresAt: {
gte: new Date(Date.now()),
},
},
{
apiKeyType,
},
],
},
});
return validKey;
};