forked from catalyst/moodle-auth_saml2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectidp.php
122 lines (100 loc) · 3.84 KB
/
selectidp.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* IdP selection GUI.
*
* @package auth_saml2
* @author Rossco Hellmans <[email protected]>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use auth_saml2\admin\saml2_settings;
// @codingStandardsIgnoreStart
require_once(__DIR__ . '/../../config.php');
// @codingStandardsIgnoreEnd
require('setup.php');
$site = get_site();
$loginsite = get_string("loginsite");
$PAGE->set_context(context_system::instance());
$PAGE->set_url(new moodle_url('/auth/saml2/selectidp.php'));
$PAGE->set_title("$site->fullname: $loginsite");
$PAGE->set_heading("$site->fullname");
$PAGE->navbar->add($loginsite);
$PAGE->requires->css('/auth/saml2/styles.css');
$wants = optional_param('wants', '', PARAM_RAW);
$idpname = $saml2auth->config->idpname;
// Retrieve IdP used for login when 'rememberidp' checkbox was set.
$storedchoiceidp = $saml2auth->get_idp_cookie();
if (empty($idpname)) {
$idpname = get_string('idpnamedefault', 'auth_saml2');
}
$data = [
'metadataentities' => $saml2auth->metadataentities,
'storedchoiceidp' => $storedchoiceidp,
'wants' => $wants,
'idpname' => $idpname
];
$action = new moodle_url('/auth/saml2/selectidp.php');
$displaytype = $saml2auth->config->multiidpdisplay;
if ($displaytype == saml2_settings::OPTION_MULTI_IDP_DISPLAY_DROPDOWN) {
$mform = new \auth_saml2\form\selectidp_dropdown($action, $data);
} else if ($displaytype == saml2_settings::OPTION_MULTI_IDP_DISPLAY_BUTTONS) {
$mform = new \auth_saml2\form\selectidp_buttons($action, $data);
} else {
throw new SimpleSAML_Error_Exception('An invalid multiple IdP display type has been selected.');
}
if ($fromform = $mform->get_data()) {
$idp = required_param('idp', PARAM_RAW);
$wants = optional_param('wants', '', PARAM_RAW);
$rememberidp = optional_param('rememberidp', '', PARAM_RAW);
$params = [
'wants' => $wants,
'idp' => $idp,
'rememberidp' => $rememberidp
];
$loginurl = new moodle_url('/auth/saml2/login.php', $params);
redirect($loginurl);
} else {
$rememberidp = $storedchoiceidp !== '' ? 1 : 0;
$data = array('rememberidp' => $rememberidp);
if ($displaytype == saml2_settings::OPTION_MULTI_IDP_DISPLAY_DROPDOWN) {
$data['idp'] = $storedchoiceidp;
}
$mform->set_data($data);
// Default is if rememberidp is on.
$passive = (bool)optional_param('passive', $rememberidp, PARAM_BOOL);
// If rememberidp is set and we are not returning from a passive attempt to login.
if ($passive) {
$errorurl = $PAGE->url;
$errorurl->params(array('passive' => 0));
$params = [
'wants' => $wants,
'idp' => $storedchoiceidp,
'passive' => 1,
'errorurl' => $errorurl->out(false)
];
$loginurl = new moodle_url('/auth/saml2/login.php', $params);
redirect($loginurl);
}
}
echo $OUTPUT->header();
echo html_writer::start_div('loginbox');
echo html_writer::tag('h2', get_string('selectloginservice', 'auth_saml2'));
echo html_writer::start_div('subcontent');
$mform->display();
echo html_writer::end_div();
echo html_writer::end_div();
echo $OUTPUT->footer();