mirror of
https://github.com/netzbegruenung/user_saml.git
synced 2024-05-03 17:43:41 +02:00
03646e6159
The cookie "_SHIBSESSION_" is expected. Fixes https://github.com/nextcloud/user_saml/issues/9
66 lines
2.5 KiB
PHP
66 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
|
*
|
|
* @license GNU AGPL version 3 or any later version
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
require_once __DIR__ . '/../3rdparty/vendor/autoload.php';
|
|
|
|
\OCP\App::registerAdmin('user_saml', 'admin');
|
|
|
|
$urlGenerator = \OC::$server->getURLGenerator();
|
|
$config = \OC::$server->getConfig();
|
|
$request = \OC::$server->getRequest();
|
|
$samlSettings = new \OCA\User_SAML\SAMLSettings(
|
|
$urlGenerator,
|
|
$config
|
|
);
|
|
try {
|
|
$oneLoginSettings = new \OneLogin_Saml2_Settings($samlSettings->getOneLoginSettingsArray());
|
|
} catch(OneLogin_Saml2_Error $e) {
|
|
return;
|
|
}
|
|
|
|
$userBackend = new \OCA\User_SAML\UserBackend(
|
|
\OC::$server->getConfig(),
|
|
\OC::$server->getLogger(),
|
|
\OC::$server->getURLGenerator(),
|
|
\OC::$server->getSession()
|
|
);
|
|
OC_User::useBackend($userBackend);
|
|
OC_User::handleApacheAuth();
|
|
|
|
// Redirect all requests to the login page to the SAML login
|
|
$currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT));
|
|
if($currentUrl === '/index.php/login' && !OC_User::isLoggedIn()) {
|
|
$csrfToken = \OC::$server->getCsrfTokenManager()->getToken();
|
|
header('Location: '.$urlGenerator->linkToRouteAbsolute('user_saml.SAML.login') .'?requesttoken='. urlencode($csrfToken->getEncryptedValue()));
|
|
exit();
|
|
}
|
|
|
|
// If a request to OCS or remote.php is sent by the official desktop clients it can
|
|
// be intercepted as it supports SAML. All other clients don't yet and thus we
|
|
// require the usage of application specific passwords there.
|
|
if(substr($currentUrl, 0, 12) === '/remote.php/' || substr($currentUrl, 0, 5) === '/ocs/') {
|
|
if(!OC_User::isLoggedIn() && $request->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_OWNCLOUD_DESKTOP])) {
|
|
$csrfToken = \OC::$server->getCsrfTokenManager()->getToken();
|
|
header('Location: '.$urlGenerator->linkToRouteAbsolute('user_saml.SAML.login') .'?requesttoken='. urlencode($csrfToken->getEncryptedValue()));
|
|
exit();
|
|
}
|
|
}
|