From 74a30a180e2b98b9dc429774f46be7947e869f0c Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 8 Mar 2023 00:03:16 +0530 Subject: [PATCH] URL to initiate SAML authentication flow (#6813) Co-authored-by: Peer Richelsen --- apps/web/pages/auth/sso/direct.tsx | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 apps/web/pages/auth/sso/direct.tsx diff --git a/apps/web/pages/auth/sso/direct.tsx b/apps/web/pages/auth/sso/direct.tsx new file mode 100644 index 0000000000..23b0a66be4 --- /dev/null +++ b/apps/web/pages/auth/sso/direct.tsx @@ -0,0 +1,38 @@ +import { signIn } from "next-auth/react"; +import { useRouter } from "next/router"; + +import { samlProductID, samlTenantID } from "@calcom/features/ee/sso/lib/saml"; +import { HOSTED_CAL_FEATURES } from "@calcom/lib/constants"; + +import type { inferSSRProps } from "@lib/types/inferSSRProps"; + +// This page is used to initiate the SAML authentication flow by redirecting to the SAML provider. +// Accessible only on self-hosted Cal.com instances. +export default function Page({ samlTenantID, samlProductID }: inferSSRProps) { + const router = useRouter(); + + if (HOSTED_CAL_FEATURES) { + router.push("/auth/login"); + return; + } + + // Initiate SAML authentication flow + signIn( + "saml", + { + callbackUrl: "/", + }, + { tenant: samlTenantID, product: samlProductID } + ); + + return null; +} + +export async function getServerSideProps() { + return { + props: { + samlTenantID, + samlProductID, + }, + }; +}