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\discovery\openidconnect;
20
use core\oauth2\issuer;
21
 
22
/**
23
 * Class linkedin.
24
 *
25
 * OAuth 2 issuer for linkedin which is mostly OIDC compliant, with a few notable exceptions which require working around:
26
 *
27
 * 1. LinkedIn don't provide their OIDC discovery doc at {ISSUER}/.well-known/openid-configuration as the spec requires.
28
 * i.e. https://www.linkedin.com/.well-known/openid-configuration isn't present.
29
 * Instead, they make the configuration available at https://www.linkedin.com/oauth/.well-known/openid-configuration.
30
 * See: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig
31
 *
32
 * 2. LinkedIn don't return 'locale' as a string in the userinfo but instead return an object with 'language' and 'country' props.
33
 * See: https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
34
 * This is resolved in {@see \core\oauth2\client\linkedin::get_userinfo()}
35
 *
36
 * @copyright  2021 Peter Dias
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 * @package    core
39
 */
40
class linkedin extends openidconnect {
41
    /**
42
     * Build an OAuth2 issuer, with all the default values for this service.
43
     *
44
     * @return issuer The issuer initialised with proper default values.
45
     */
46
    public static function init(): issuer {
47
        $record = (object) [
48
            'name' => 'LinkedIn',
49
            'image' => 'https://static.licdn.com/scds/common/u/images/logos/favicons/v1/favicon.ico',
50
            'baseurl' => 'https://www.linkedin.com/oauth', // The /oauth is where .well-known/openid-configuration lives.
51
            'loginscopes' => 'openid profile email',
52
            'loginscopesoffline' => 'openid profile email',
53
            'showonloginpage' => issuer::EVERYWHERE,
54
            'servicetype' => 'linkedin',
55
        ];
56
 
57
        $issuer = new issuer(0, $record);
58
        return $issuer;
59
    }
60
}