From e06acbe7384c1deae7c057e6b458ac7438d56bd9 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 27 Oct 2022 10:43:33 +0200 Subject: [PATCH] Put back ExternalSso for #585 Not the most secure, needs improvements --- .../libraries/RainLoop/Config/Application.php | 2 ++ .../app/libraries/RainLoop/ServiceActions.php | 31 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php index 8fedbda4b..17e524fa0 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php @@ -387,6 +387,8 @@ Enables caching in the system'), 'custom_login_link' => array(''), 'custom_logout_link' => array(''), 'allow_external_login' => array(false), + 'allow_external_sso' => array(false), + 'external_sso_key' => array(''), 'http_client_ip_check_proxy' => array(false), 'fast_cache_memcache_host' => array('127.0.0.1'), 'fast_cache_memcache_port' => array(11211), diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index d8d744b21..039c7c142 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -811,10 +811,33 @@ class ServiceActions return ''; } - /** - * @return mixed - */ - public function ErrorTemplates(string $sTitle, string $sDesc, bool $bShowBackLink = true) + public function ServiceExternalSso() : string + { + $this->oHttp->ServerNoCache(); + $sResult = ''; + $oConfig = $this->oActions->Config(); + $sKey = $oConfig->Get('labs', 'external_sso_key', ''); + $sEmail = \trim($this->oHttp->GetRequest('Email', '')); + $sPassword = $this->oHttp->GetRequest('Password', ''); + if ($oConfig->Get('labs', 'allow_external_sso', false) + && $sEmail && $sPassword + && $sKey && $this->oHttp->GetRequest('SsoKey', '') == $sKey + ) { + $sResult = \RainLoop\Api::CreateUserSsoHash($sEmail, $sPassword); + if ('json' == \strtolower($this->oHttp->GetRequest('Output', 'Plain'))) { + \header('Content-Type: application/json; charset=utf-8'); + $sResult = \json_encode(array( + 'Action' => 'ExternalSso', + 'Result' => $sResult + )); + } else { + \header('Content-Type: text/plain'); + } + } + return $sResult; + } + + public function ErrorTemplates(string $sTitle, string $sDesc, bool $bShowBackLink = true) : string { return \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Error.html'), array( '{{ErrorTitle}}' => $sTitle,