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\client;
|
|
|
18 |
|
|
|
19 |
use core\oauth2\client;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Class linkedin - Custom client handler to fetch data from linkedin
|
|
|
23 |
*
|
|
|
24 |
* Custom oauth2 client for linkedin as it doesn't support OIDC and has a different way to get
|
|
|
25 |
* key information for users - firstname, lastname, email.
|
|
|
26 |
*
|
|
|
27 |
* @copyright 2021 Peter Dias
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
* @package core
|
|
|
30 |
*/
|
|
|
31 |
class linkedin extends client {
|
|
|
32 |
/**
|
|
|
33 |
* Override to handle LinkedIn's non-spec-compliant 'locale' field, which isn't a string (e.g. 'en-US') but an object.
|
|
|
34 |
*
|
|
|
35 |
* @return array|false
|
|
|
36 |
*/
|
|
|
37 |
public function get_userinfo() {
|
|
|
38 |
$rawuserinfo = $this->get_raw_userinfo();
|
|
|
39 |
if ($rawuserinfo === false) {
|
|
|
40 |
return false;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
if (!empty($rawuserinfo->locale) && is_object($rawuserinfo->locale)) {
|
|
|
44 |
if (!empty($rawuserinfo->locale->language) && !empty($rawuserinfo->locale->country)) {
|
|
|
45 |
$rawuserinfo->locale = "{$rawuserinfo->locale->language}-{$rawuserinfo->locale->country}";
|
|
|
46 |
} else {
|
|
|
47 |
unset($rawuserinfo->locale);
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
return $this->map_userinfo_to_fields($rawuserinfo);
|
|
|
52 |
}
|
|
|
53 |
}
|