/** * @param string $sPath * @param string $sEmail * @param string $sPassword * * @return string */ public static function getSsoHash($sPath, $sEmail, $sPassword) { $SsoHash = ''; $sPath = rtrim(trim($sPath), '\\/') . '/index.php'; if (file_exists($sPath)) { $_ENV['RAINLOOP_INCLUDE_AS_API'] = true; include $sPath; if (class_exists('\\RainLoop\\Api')) { $SsoHash = \RainLoop\Api::GetUserSsoHash($sEmail, $sPassword); } } return $SsoHash; }
/** * @return string */ public function ServiceExternalSso() { $sResult = ''; $bLogout = true; $sKey = $this->oActions->Config()->Get('labs', 'external_sso_key', ''); if ($this->oActions->Config()->Get('labs', 'allow_external_sso', false) && !empty($sKey) && $sKey === \trim($this->oHttp->GetRequest('SsoKey', ''))) { $sEmail = \trim($this->oHttp->GetRequest('Email', '')); $sPassword = $this->oHttp->GetRequest('Password', ''); $sResult = \RainLoop\Api::GetUserSsoHash($sEmail, $sPassword); $bLogout = 0 === \strlen($sResult); switch (\strtolower($this->oHttp->GetRequest('Output', 'Plain'))) { case 'plain': @\header('Content-Type: text/plain'); break; case 'json': @\header('Content-Type: application/json; charset=utf-8'); $sResult = \MailSo\Base\Utils::Php2js(array('Action' => 'ExternalSso', 'Result' => $sResult), $this->Logger()); break; } } if ($bLogout) { $this->oActions->SetAuthLogoutToken(); } return $sResult; }
<?php // Enable RainLoop Api and include index file $_ENV['RAINLOOP_INCLUDE_AS_API'] = true; include '/var/www/rainloop/app/index.php'; // Retrieve email and password if (isset($_SERVER['HTTP_EMAIL']) && isset($_SERVER['PHP_AUTH_PW'])) { $email = $_SERVER['HTTP_EMAIL']; $password = $_SERVER['PHP_AUTH_PW']; $ssoHash = \RainLoop\Api::GetUserSsoHash($email, $password); // redirect to webmail sso url \header('Location: https://domain.tldPATHTOCHANGE/app/index.php?sso&hash=' . $ssoHash); } else { \header('Location: https://domain.tldPATHTOCHANGE/app/index.php'); }