Merge branch 'MDL-78308-402' of https://github.com/paulholden/moodle into MOODLE_402_...
[moodle.git] / auth / oauth2 / auth.php
blob76700d7cd5506ab64579d81aafc757954d0471a5
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Open ID authentication.
20 * @package auth_oauth2
21 * @copyright 2017 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->libdir.'/authlib.php');
29 /**
30 * Plugin for oauth2 authentication.
32 * @package auth_oauth2
33 * @copyright 2017 Damyon Wiese
34 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
36 class auth_plugin_oauth2 extends \auth_oauth2\auth {
38 /**
39 * Test the various configured Oauth2 providers.
41 public function test_settings() {
42 global $OUTPUT;
44 $authplugin = get_auth_plugin('oauth2');
45 $idps = $authplugin->loginpage_idp_list('');
46 $templateidps = [];
48 if (empty($idps)) {
49 echo $OUTPUT->notification(get_string('noconfiguredidps', 'auth_oauth2'), 'notifyproblem');
50 return;
51 } else {
52 foreach ($idps as $idp) {
53 $idpid = $idp['url']->get_param('id');
54 $sesskey = $idp['url']->get_param('sesskey');
55 $testurl = new moodle_url('/auth/oauth2/test.php', ['id' => $idpid, 'sesskey' => $sesskey]);
57 $templateidps[] = ['name' => $idp['name'], 'url' => $testurl->out(), 'iconurl' => $idp['iconurl']];
59 echo $OUTPUT->render_from_template('auth_oauth2/idps', ['idps' => $templateidps]);