Exemple #1
0
<?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/>.
/**
 * @package auth_oidc
 * @author James McQuillan <*****@*****.**>
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright (C) 2014 onwards Microsoft Open Technologies, Inc. (http://msopentech.com/)
 */
require_once __DIR__ . '/../../config.php';
require_once __DIR__ . '/auth.php';
$auth = new \auth_plugin_oidc('authcode');
$auth->set_httpclient(new \auth_oidc\httpclient());
$auth->handleredirect();
Exemple #2
0
 /**
  * Disconnect from o365.
  */
 public function mode_disconnecttoken()
 {
     global $CFG;
     require_once $CFG->dirroot . '/auth/oidc/auth.php';
     $auth = new \auth_plugin_oidc();
     $auth->set_httpclient(new \auth_oidc\httpclient());
     $redirect = new \moodle_url('/local/o365/ucp.php');
     $auth->disconnect(true, $redirect);
 }
Exemple #3
0
$oidctoken = $DB->get_record('auth_oidc_token', ['username' => $USER->username]);
$oidcconnected = !empty($oidctoken) ? true : false;
$oidcloginconnected = $USER->auth === 'oidc' ? true : false;
if (!empty($action)) {
    if ($action === 'connectlogin' && $oidcloginconnected === false) {
        // Use authorization request login flow to connect existing users.
        if (!is_enabled_auth('oidc')) {
            throw new \moodle_exception('erroroidcnotenabled', 'auth_oidc');
        }
        $auth = new \auth_oidc\loginflow\authcode();
        $auth->set_httpclient(new \auth_oidc\httpclient());
        $auth->initiateauthrequest();
    } else {
        if ($action === 'disconnectlogin' && $oidcloginconnected === true) {
            if (is_enabled_auth('manual') === true) {
                $auth = new \auth_plugin_oidc();
                $auth->set_httpclient(new \auth_oidc\httpclient());
                $auth->disconnect();
            }
        } else {
            throw new \moodle_exception('errorucpinvalidaction', 'auth_oidc');
        }
    }
} else {
    $PAGE->set_url('/auth/oidc/ucp.php');
    $usercontext = \context_user::instance($USER->id);
    $PAGE->set_context(\context_system::instance());
    $PAGE->set_pagelayout('standard');
    $USER->editing = false;
    $authconfig = get_config('auth_oidc');
    $opname = !empty($authconfig->opname) ? $authconfig->opname : get_string('pluginname', 'auth_oidc');