Test Setup Failed
Push — master ( 4e700f...c7183e )
by Julito
63:12
created

SsoServer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getUrl() 0 40 6
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * This file contains the necessary elements to implement a Single Sign On
6
 * using chamilo as a SSO server
7
 * @package chamilo.auth.sso
8
 */
9
class SsoServer
10
{
11
    /**
12
     * This is used to get the url with the SSO params
13
     * @param string $refererSso
14
     * @param array $additionalParams
15
     * @return string
16
     */
17
    public function getUrl($refererSso, $additionalParams = array())
18
    {
19
        if (empty($refererSso)) {
20
            return null;
21
        }
22
23
        $getParams = parse_url($refererSso, PHP_URL_QUERY);
24
        $userInfo = api_get_user_info(api_get_user_id(), false, true);
25
        $chamiloUrl = api_get_path(WEB_PATH);
26
        $sso = [
27
            'username' => $userInfo['username'],
28
            'secret' => sha1($userInfo['password']),
29
            'master_domain' => $chamiloUrl,
30
            'master_auth_uri' => $chamiloUrl.'?submitAuth=true',
31
            'lifetime' => time() + 3600,
32
            'target' => $refererSso,
33
        ];
34
35
        if (!empty($additionalParams)) {
36
            foreach ($additionalParams as $key => $value) {
37
                if (!empty($key)) {
38
                    $sso[$key] = $value;
39
40
                    continue;
41
                }
42
43
                $sso[] = $value;
44
            }
45
        }
46
47
        $cookie = base64_encode(serialize($sso));
48
49
        return $refererSso
50
            .($getParams ? '&' : '?')
51
            .http_build_query([
52
                'loginFailed' => 0,
53
                'sso_referer' => $refererSso,
54
                'sso_cookie' => $cookie
55
            ]);
56
    }
57
}
58