Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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.
  13  //
  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/>.
  16  
  17  /**
  18   * Open ID authentication.
  19   *
  20   * @package auth_oauth2
  21   * @copyright 2017 Damyon Wiese
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->libdir.'/authlib.php');
  28  
  29  /**
  30   * Plugin for oauth2 authentication.
  31   *
  32   * @package auth_oauth2
  33   * @copyright 2017 Damyon Wiese
  34   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  35   */
  36  class auth_plugin_oauth2 extends \auth_oauth2\auth {
  37  
  38      /**
  39       * Test the various configured Oauth2 providers.
  40       */
  41      public function test_settings() {
  42          global $OUTPUT;
  43  
  44          $authplugin = get_auth_plugin('oauth2');
  45          $idps = $authplugin->loginpage_idp_list('');
  46          $templateidps = [];
  47  
  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]);
  56  
  57                  $templateidps[] = ['name' => $idp['name'], 'url' => $testurl->out(), 'iconurl' => $idp['iconurl']];
  58              }
  59              echo $OUTPUT->render_from_template('auth_oauth2/idps', ['idps' => $templateidps]);
  60          }
  61      }
  62  }
  63  
  64