Skip to content

Commit 0961079

Browse files
authored
Merge pull request #1 from adlnet/moodle-4.4-updates
Moodle 4.4 updates
2 parents 28ff32e + 9951d29 commit 0961079

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git
2+
update.sh

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scratch
2+
update.sh

auth.php

+34-24
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public function loginpage_hook() {
7474
private function attempt_jwt_login() {
7575
global $CFG, $DB;
7676

77-
$authtoken = null;
78-
$authtokenRaw = null;
77+
$authHeader = null;
7978

8079
/**
8180
* Most deployments will be through Apache, at least for ADL, so
@@ -84,7 +83,7 @@ private function attempt_jwt_login() {
8483
if (function_exists('apache_request_headers')) {
8584
$headers = apache_request_headers();
8685
if (isset($headers['Authorization'])) {
87-
$authtokenRaw = $headers['Authorization'];
86+
$authHeader = $headers['Authorization'];
8887
}
8988
}
9089

@@ -93,26 +92,21 @@ private function attempt_jwt_login() {
9392
* will miss the previous check, so we can also check the older syntax
9493
* if necessary.
9594
*/
96-
if (!isset($authtokenRaw)) {
95+
if (!isset($authHeader)) {
9796
if (isset($_SERVER['Authorization'])) {
98-
$authtokenRaw = $_SERVER['Authorization'];
97+
$authHeader = $_SERVER['Authorization'];
9998
}
10099
else if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
101-
$authtokenRaw = $_SERVER['HTTP_AUTHORIZATION'];
100+
$authHeader = $_SERVER['HTTP_AUTHORIZATION'];
102101
}
103102
}
104103

105-
if (!isset($authtokenRaw))
104+
if (!isset($authHeader))
106105
return;
107106

108-
$authtoken = trim(substr($authtokenRaw, 7));
109-
$token_parts = explode('.', $authtoken);
110-
111-
$headerEncoded = $token_parts[0];
112-
$payloadEncoded = $token_parts[1];
113-
$signatureEncoded = $token_parts[2];
114-
115-
$payload = $this->parse_jwt_component($payloadEncoded);
107+
$payload = $this->parse_jwt_component($authHeader);
108+
if (is_null($payload))
109+
return;
116110

117111
/**
118112
* We allow the environment to specify whether to perform an issuer check.
@@ -233,8 +227,8 @@ private function attempt_jwt_login() {
233227
private function get_expected_username($cert) {
234228

235229
$envEDIPIProperty = getenv("MOODLE_JWT_EDIPI_PROPERTY");
236-
237230
$useEDIPI = $this->has_env_bool("MOODLE_JWT_USE_EDIPI");
231+
238232
$configuredForEDIPI = $envEDIPIProperty != false;
239233

240234
if ($useEDIPI && $configuredForEDIPI) {
@@ -247,14 +241,17 @@ private function get_expected_username($cert) {
247241
}
248242

249243
$envCustomProperty = getenv("MOODLE_JWT_USERNAME_PROPERTY");
250-
251244
$useCustomProperty = $envCustomProperty != false;
252-
$hasCustomProperty = property_exists($cert, $envCustomProperty);
253-
254-
if ($useCustomProperty && $hasCustomProperty) {
255-
return $cert->$envCustomProperty;
245+
246+
if ($useCustomProperty) {
247+
248+
$hasCustomProperty = property_exists($cert, $envCustomProperty);
249+
if ($hasCustomProperty) {
250+
return $cert->$envCustomProperty;
251+
}
256252
}
257253

254+
258255
return $this->get_default_username($cert);
259256
}
260257

@@ -298,11 +295,24 @@ private function get_default_username($cert) {
298295
return $cert->preferred_username;
299296
}
300297

301-
private function parse_jwt_component($encodedStr) {
298+
private function parse_jwt_component($authHeader) {
302299

303-
$decodedStr = $this->decode_base_64($encodedStr);
304-
$jsonObj = json_decode($decodedStr);
300+
if (strlen($authHeader) < 7)
301+
return null;
302+
303+
$authtoken = trim(substr($authHeader, 7));
304+
$token_parts = explode('.', $authtoken);
305305

306+
if (count($token_parts) != 3)
307+
return null;
308+
309+
$headerEncoded = $token_parts[0];
310+
$payloadEncoded = $token_parts[1];
311+
$signatureEncoded = $token_parts[2];
312+
313+
$decodedStr = $this->decode_base_64($payloadEncoded);
314+
$jsonObj = json_decode($decodedStr);
315+
306316
return $jsonObj;
307317
}
308318

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626

27-
$plugin->version = 2023110900; // The current plugin version (Date: YYYYMMDDXX).
27+
$plugin->version = 2024042600; // The current plugin version (Date: YYYYMMDDXX).
2828
$plugin->requires = 2022111800; // Requires this Moodle version.
2929
$plugin->component = 'auth_jwt'; // Full name of the plugin (used for diagnostics)

0 commit comments

Comments
 (0)