Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439 Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
/* For licensing terms, see /license.txt */
|
|
|
|
/**
|
|
* This file contains the necessary elements to implement a Single Sign On
|
|
* using chamilo as a SSO server.
|
|
*
|
|
* @package chamilo.auth.sso
|
|
*/
|
|
class SsoServer
|
|
{
|
|
/**
|
|
* This is used to get the url with the SSO params.
|
|
*
|
|
* @param string $refererSso
|
|
* @param array $additionalParams
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getUrl($refererSso, $additionalParams = [])
|
|
{
|
|
if (empty($refererSso)) {
|
|
return null;
|
|
}
|
|
|
|
$getParams = parse_url($refererSso, PHP_URL_QUERY);
|
|
$userInfo = api_get_user_info(api_get_user_id(), false, true);
|
|
$chamiloUrl = api_get_path(WEB_PATH);
|
|
$sso = [
|
|
'username' => $userInfo['username'],
|
|
'secret' => sha1($userInfo['password']),
|
|
'master_domain' => $chamiloUrl,
|
|
'master_auth_uri' => $chamiloUrl.'?submitAuth=true',
|
|
'lifetime' => time() + 3600,
|
|
'target' => $refererSso,
|
|
];
|
|
|
|
if (!empty($additionalParams)) {
|
|
foreach ($additionalParams as $key => $value) {
|
|
if (!empty($key)) {
|
|
$sso[$key] = $value;
|
|
|
|
continue;
|
|
}
|
|
|
|
$sso[] = $value;
|
|
}
|
|
}
|
|
|
|
$cookie = base64_encode(serialize($sso));
|
|
|
|
return $refererSso
|
|
.($getParams ? '&' : '?')
|
|
.http_build_query([
|
|
'loginFailed' => 0,
|
|
'sso_referer' => $refererSso,
|
|
'sso_cookie' => $cookie,
|
|
]);
|
|
}
|
|
}
|