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-02 18:15:28 +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
|
|
|
};
|
|
|
|
|
|
|
|
let connectionController: IConnectionAPIController;
|
|
|
|
let oauthController: IOAuthController;
|
|
|
|
let samlSPConfig: ISPSAMLConfig;
|
|
|
|
|
2023-02-17 13:21:29 +00:00
|
|
|
const g = global;
|
|
|
|
|
|
|
|
declare global {
|
|
|
|
var connectionController: IConnectionAPIController | undefined;
|
|
|
|
var oauthController: IOAuthController | undefined;
|
|
|
|
var samlSPConfig: ISPSAMLConfig | undefined;
|
|
|
|
}
|
2022-10-18 20:34:32 +00:00
|
|
|
|
|
|
|
export default async function init() {
|
2023-02-17 13:21:29 +00:00
|
|
|
if (!g.connectionController || !g.oauthController || !g.samlSPConfig) {
|
2022-10-18 20:34:32 +00:00
|
|
|
const ret = await jackson(opts);
|
|
|
|
|
|
|
|
connectionController = ret.connectionAPIController;
|
|
|
|
oauthController = ret.oauthController;
|
|
|
|
samlSPConfig = ret.spConfig;
|
|
|
|
|
|
|
|
g.connectionController = connectionController;
|
|
|
|
g.oauthController = oauthController;
|
|
|
|
g.samlSPConfig = samlSPConfig;
|
|
|
|
} else {
|
|
|
|
connectionController = g.connectionController;
|
|
|
|
oauthController = g.oauthController;
|
|
|
|
samlSPConfig = g.samlSPConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
connectionController,
|
|
|
|
oauthController,
|
|
|
|
samlSPConfig,
|
|
|
|
};
|
|
|
|
}
|