2023-03-02 18:15:28 +00:00
|
|
|
import jackson from "@boxyhq/saml-jackson";
|
2023-02-17 13:21:29 +00:00
|
|
|
import type {
|
2022-10-18 20:34:32 +00:00
|
|
|
IConnectionAPIController,
|
|
|
|
IOAuthController,
|
|
|
|
JacksonOption,
|
|
|
|
ISPSAMLConfig,
|
|
|
|
} from "@boxyhq/saml-jackson";
|
|
|
|
|
2023-03-10 15:28:57 +00:00
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
2022-10-18 20:34:32 +00:00
|
|
|
|
2023-03-07 21:31:39 +00:00
|
|
|
import { samlDatabaseUrl, samlAudience, samlPath, oidcPath, clientSecretVerifier } from "./saml";
|
2022-10-18 20:34:32 +00:00
|
|
|
|
|
|
|
// Set the required options. Refer to https://github.com/boxyhq/jackson#configuration for the full list
|
|
|
|
const opts: JacksonOption = {
|
|
|
|
externalUrl: WEBAPP_URL,
|
|
|
|
samlPath,
|
|
|
|
samlAudience,
|
2023-01-24 20:02:43 +00:00
|
|
|
oidcPath,
|
2022-10-18 20:34:32 +00:00
|
|
|
db: {
|
|
|
|
engine: "sql",
|
|
|
|
type: "postgres",
|
|
|
|
url: samlDatabaseUrl,
|
|
|
|
encryptionKey: process.env.CALENDSO_ENCRYPTION_KEY,
|
|
|
|
},
|
2023-03-07 21:31:39 +00:00
|
|
|
idpEnabled: true,
|
|
|
|
clientSecretVerifier,
|
2022-10-18 20:34:32 +00:00
|
|
|
};
|
|
|
|
|
2023-02-17 13:21:29 +00:00
|
|
|
declare global {
|
2023-03-10 15:28:57 +00:00
|
|
|
/* eslint-disable no-var */
|
2023-02-17 13:21:29 +00:00
|
|
|
var connectionController: IConnectionAPIController | undefined;
|
|
|
|
var oauthController: IOAuthController | undefined;
|
|
|
|
var samlSPConfig: ISPSAMLConfig | undefined;
|
2023-03-10 15:28:57 +00:00
|
|
|
/* eslint-enable no-var */
|
2023-02-17 13:21:29 +00:00
|
|
|
}
|
2022-10-18 20:34:32 +00:00
|
|
|
|
|
|
|
export default async function init() {
|
2023-03-10 15:28:57 +00:00
|
|
|
if (!globalThis.connectionController || !globalThis.oauthController || !globalThis.samlSPConfig) {
|
2022-10-18 20:34:32 +00:00
|
|
|
const ret = await jackson(opts);
|
2023-03-10 15:28:57 +00:00
|
|
|
globalThis.connectionController = ret.connectionAPIController;
|
|
|
|
globalThis.oauthController = ret.oauthController;
|
|
|
|
globalThis.samlSPConfig = ret.spConfig;
|
2022-10-18 20:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2023-03-10 15:28:57 +00:00
|
|
|
connectionController: globalThis.connectionController,
|
|
|
|
oauthController: globalThis.oauthController,
|
|
|
|
samlSPConfig: globalThis.samlSPConfig,
|
2022-10-18 20:34:32 +00:00
|
|
|
};
|
|
|
|
}
|