Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace core\oauth2\service;
18
 
19
use core\oauth2\issuer;
20
use core\oauth2\discovery\openidconnect;
21
use core\oauth2\user_field_mapping;
22
 
23
/**
24
 * Class for Clever OAuth service, with the specific methods related to it.
25
 *
26
 * @package    core
27
 * @copyright  2022 OpenStax
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class clever extends openidconnect implements issuer_interface {
31
    /**
32
     * Build an OAuth2 issuer, with all the default values for this service.
33
     *
34
     * @return issuer The issuer initialised with proper default values.
35
     */
36
    public static function init(): issuer {
37
        $record = (object) [
38
            'name' => 'Clever',
39
            'image' => 'https://apps.clever.com/favicon.ico',
40
            'basicauth' => 1,
41
            'baseurl' => 'https://clever.com',
42
            'showonloginpage' => issuer::LOGINONLY,
43
            'servicetype' => 'clever',
44
        ];
45
 
46
        return new issuer(0, $record);
47
    }
48
 
49
    /**
50
     * Create field mappings for this issuer.
51
     *
52
     * @param issuer $issuer Issuer the field mappings should be created for.
53
     */
54
    public static function create_field_mappings(issuer $issuer): void {
55
        // Perform OIDC default field mapping.
56
        parent::create_field_mappings($issuer);
57
 
58
        // Create the additional 'sub' field mapping.
59
        $record = (object) [
60
            'issuerid' => $issuer->get('id'),
61
            'externalfield' => 'sub',
62
            'internalfield' => 'idnumber',
63
        ];
64
        $userfieldmapping = new user_field_mapping(0, $record);
65
        $userfieldmapping->create();
66
    }
67
}