Identity Providers): agents and * client contacts signing in with Microsoft 365, Google Workspace, Nextcloud or their mail * password (IMAP). identity_providers - each one's kind and name, whether it is on, who it signs * in (agents, contacts) and on which email domains, whether it is required, its app's ID and * secret, its tenant (Microsoft), address (Nextcloud, or the IMAP server with its port, security * and username style), the path it sends people back to, and when it was last used. * * The Microsoft Entra app the client portal signed in with (settings.config_azure_client_id and * config_azure_client_secret) becomes the first provider, for client contacts on any domain, still * sending them back to /client/login_microsoft.php - the address registered with it - with its * secret sealed (secretSeal()), and the two settings go. Contacts set to sign in with Microsoft keep that (users.user_auth_method azure), * now meaning through an identity provider, without a password. Re-runnable. */ defined('FROM_DB_UPDATER') || die("Direct file access is not allowed"); mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `identity_providers` ( `identity_provider_id` int(11) NOT NULL AUTO_INCREMENT, `identity_provider_kind` varchar(20) NOT NULL, `identity_provider_name` varchar(100) NOT NULL, `identity_provider_enabled` tinyint(1) NOT NULL DEFAULT 1, `identity_provider_agents` tinyint(1) NOT NULL DEFAULT 0, `identity_provider_contacts` tinyint(1) NOT NULL DEFAULT 0, `identity_provider_domains` varchar(1000) NOT NULL DEFAULT '', `identity_provider_required` tinyint(1) NOT NULL DEFAULT 0, `identity_provider_client_id` varchar(255) NOT NULL DEFAULT '', `identity_provider_client_secret` varchar(1000) NOT NULL DEFAULT '', `identity_provider_tenant` varchar(100) NOT NULL DEFAULT '', `identity_provider_url` varchar(500) NOT NULL DEFAULT '', `identity_provider_port` int(11) NOT NULL DEFAULT 0, `identity_provider_security` varchar(10) NOT NULL DEFAULT '', `identity_provider_username` varchar(10) NOT NULL DEFAULT '', `identity_provider_redirect_path` varchar(100) NOT NULL DEFAULT '/login_provider.php', `identity_provider_used_at` datetime DEFAULT NULL, `identity_provider_created_at` datetime NOT NULL DEFAULT current_timestamp(), `identity_provider_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), PRIMARY KEY (`identity_provider_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"); // The client portal's Microsoft Entra app, as the first provider - once $itflow_azure_column = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'settings' AND COLUMN_NAME = 'config_azure_client_id' LIMIT 1"); if ($itflow_azure_column && mysqli_num_rows($itflow_azure_column) > 0) { $itflow_azure = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT config_azure_client_id, config_azure_client_secret FROM settings WHERE company_id = 1")); $itflow_azure_id = trim((string) ($itflow_azure['config_azure_client_id'] ?? '')); $itflow_azure_secret = trim((string) ($itflow_azure['config_azure_client_secret'] ?? '')); $itflow_providers = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM identity_providers"))[0] ?? 0); if ($itflow_azure_id !== '' && $itflow_providers === 0) { // Its secret sealed with this install's key, as one typed in Admin > Identity Providers is (secretSeal()) - kept as it // was when the install can't make a key, or this run started on code from before it, and read as it is $itflow_azure_sealed = function_exists('secretSeal') && $itflow_azure_secret !== '' ? secretSeal($itflow_azure_secret, 'identity-provider') : ''; $itflow_azure_secret = $itflow_azure_sealed !== '' ? $itflow_azure_sealed : $itflow_azure_secret; mysqli_query($mysqli, "INSERT INTO identity_providers SET identity_provider_kind = 'microsoft', identity_provider_name = 'Microsoft 365', identity_provider_enabled = 1, identity_provider_agents = 0, identity_provider_contacts = 1, identity_provider_client_id = '" . mysqli_real_escape_string($mysqli, $itflow_azure_id) . "', identity_provider_client_secret = '" . mysqli_real_escape_string($mysqli, $itflow_azure_secret) . "', identity_provider_redirect_path = '/client/login_microsoft.php'"); } mysqli_query($mysqli, "ALTER TABLE `settings` DROP COLUMN `config_azure_client_id`, DROP COLUMN `config_azure_client_secret`"); }