Files
OpenAuth_server/Backend/src/api/user/oauth/_helper.ts
Fabian Stamm 0453e461c9 Restructuring the Project
Updating dependencies
2023-04-07 19:54:47 +02:00

22 lines
580 B
TypeScript

import RequestError, { HttpStatusCode } from "../../../helper/request_error";
import Client, { IClient } from "../../../models/client";
export async function getClientWithOrigin(client_id: string, origin: string) {
const client = await Client.findOne({
client_id,
});
const clientNotFoundError = new RequestError(
"Client not found!",
HttpStatusCode.BAD_REQUEST
);
if (!client) throw clientNotFoundError;
const clientUrl = new URL(client.redirect_url);
if (clientUrl.hostname !== origin) throw clientNotFoundError;
return client;
}