-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSSO.php
83 lines (72 loc) · 1.72 KB
/
SSO.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* SSO Client
*
* @author muhamad rifki
*/
require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/config.php';
// Enable debugging
phpCAS::setDebug();
// Enable verbose error messages. Disable in production!
phpCAS::setVerbose(true);
// Initialize phpCAS
phpCAS::client(CAS_VERSION_2_0, CAS_SERVER_HOST, CAS_SERVER_PORT, CAS_SERVER_URI);
// For quick testing you can disable SSL validation of the CAS server.
// THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION.
// VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL!
phpCAS::setNoCasServerValidation();
class SSO
{
public function __construct()
{}
/**
* Authenticate the user.
*
* @return bool Authentication
*/
public static function authenticate()
{
return phpCAS::forceAuthentication();
}
/**
* Check if the user is already authenticated.
*
* @return bool Authentication
*/
public static function checkAuth()
{
return phpCAS::checkAuthentication();
}
/**
* Logout from SSO with URL redirection options
* @return void
*/
public static function logout($uri = '')
{
if (!empty($uri)) {
$checkFirstUri = substr($uri, 0, 1);
if ($checkFirstUri == '/') {
$url = BASE_URL . $uri;
}
else {
$url = BASE_URL .'/'. $uri;
}
}
else {
$url = BASE_URL;
}
phpCAS::logout(['service' => $url]);
}
/**
* get user email address
* @return string
*/
public static function getUser()
{
if (self::checkAuth()) {
return phpCAS::getUser();
}
return '';
}
}