-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.php
More file actions
58 lines (47 loc) · 1.74 KB
/
Copy pathauth.php
File metadata and controls
58 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* OU-OpenID authentication plugin.
*
* @package auth_ouopenid
* @author Nick Freear, 07-March-2017.
* @copyright (c) 2017 The Open University.
*
* @link https://docs.moodle.org/dev/Authentication_plugins#Interfacing_to_API.27s
*/
require_once $CFG->libdir . '/authlib.php';
require_once __DIR__ . '/../../vendor/autoload.php';
use IET_OU\Moodle\Auth\Ouopenid\Db\User as OuUser;
class auth_plugin_ouopenid extends auth_plugin_base {
/**
* Class constructor
*
* Assigns default config values and checks for requested actions
*/
public function __construct() {
$this->authtype = 'ouopenid';
$this->pluginconfig = 'auth/' . $this->authtype;
$this->roleauth = 'auth_' . $this->authtype;
$this->errorlogtag = '[' . strtoupper($this->roleauth) . '] ';
$this->config = get_config($this->pluginconfig);
}
public static function set_user(&$resp, &$user, $fn = null) {
$oucu = null;
$identity_url = $resp->identity_url;
if ($identity_url && preg_match(OuUser::OPENID_URL_REGEX, $identity_url, $matches)) {
$oucu = $matches[ 'oucu' ];
}
if ($oucu && $user->auth == 'openid' && ( ! $user->firstname || $user->firstname === 'test' )) {
$user->firstname = $oucu;
}
/*if ($oucu && $user->auth == 'openid' && ! $user->email) {
$user->email = $oucu . '@openmail.open.ac.uk';
}*/
// Was: OuUser::setMoodleUser($oucu, $user, $fn);
self::debug([
__FUNCTION__, $identity_url, $oucu, $user->email, $user->username, 'userid=', $user->id, $user->profile ]);
}
public static function debug($obj) {
return OuUser::debug($obj);
}
}
// End.