Files
calendar/packages/trpc/server/routers/viewer/sso/updateOIDC.handler.ts
T
1eeb91a793 perf: lazy load tRPC routes (#8167)
* experiment: cold start perf

* fix: update failing test

* chore: add database indexes

* chore: use json protocol and add query batching back

* Update [status].tsx

* Update [trpc].ts

* Delete getSlimSession.ts

* Update createContext.ts

* remove trpc caller

* correctly import Prisma

* lazy ethRouter

* replace crypto with md5

* import fixes

* public event endpoint refactor

* Update yarn.lock

* Update yarn.lock

* Using yarn.lock from main

---------

Co-authored-by: Omar López <zomars@me.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Efraín Rochín <roae.85@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2023-04-25 19:39:47 -03:00

45 lines
1.4 KiB
TypeScript

import jackson from "@calcom/features/ee/sso/lib/jackson";
import { canAccess, samlProductID, samlTenantID, tenantPrefix } from "@calcom/features/ee/sso/lib/saml";
import { TRPCError } from "@trpc/server";
import type { TrpcSessionUser } from "../../../trpc";
import type { TUpdateOIDCInputSchema } from "./updateOIDC.schema";
type UpdateOIDCOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TUpdateOIDCInputSchema;
};
export const updateOIDCHandler = async ({ ctx, input }: UpdateOIDCOptions) => {
const { teamId, clientId, clientSecret, wellKnownUrl } = input;
const { message, access } = await canAccess(ctx.user, teamId);
if (!access) {
throw new TRPCError({
code: "BAD_REQUEST",
message,
});
}
const { connectionController } = await jackson();
try {
return await connectionController.createOIDCConnection({
defaultRedirectUrl: `${process.env.NEXT_PUBLIC_WEBAPP_URL}/api/auth/saml/idp`,
redirectUrl: JSON.stringify([`${process.env.NEXT_PUBLIC_WEBAPP_URL}/*`]),
tenant: teamId ? tenantPrefix + teamId : samlTenantID,
product: samlProductID,
oidcClientId: clientId,
oidcClientSecret: clientSecret,
oidcDiscoveryUrl: wellKnownUrl,
});
} catch (err) {
console.error("Error updating OIDC connection", err);
throw new TRPCError({ code: "BAD_REQUEST", message: "Updating OIDC Connection failed." });
}
};