Skip to content

Commit a15d0de

Browse files
committed
allowing optional properties for password gen
1 parent 9f9fa41 commit a15d0de

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

auth.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,28 @@ private function attempt_jwt_login() {
164164
/**
165165
* The "salt" here will simply be a character block to satisfy password reqs.
166166
*
167-
* The Nonce, Issuer, and JWT ID are all relatively obscure, so the idea is to
168-
* concatenate them with the requirements - ensure Moodle accepts it.
167+
* There are several fairly random properties to choose from, but we will leave
168+
* the specification to the configuration folks. If not specified, then we will
169+
* use JWT-standard properties in their place.
169170
*/
170171
$requirementSalt = "aA_12345678";
171-
$password = $payload->iss . $payload->sub . $payload->nonce . $requirementSalt;
172+
173+
$envPropertyFirst = getenv("MOODLE_JWT_ASSIGN_RANDOM_PASSWORD_PROPERTY_FIRST");
174+
$envPropertySecond = getenv("MOODLE_JWT_ASSIGN_RANDOM_PASSWORD_PROPERTY_SECOND");
175+
176+
$firstChunk = $payload->sub;
177+
$secondChunk = $payload->iss;
178+
179+
if (isset($envPropertyFirst) && $envPropertyFirst) {
180+
$firstChunk = $payload->$envPropertyFirst;
181+
}
182+
183+
if (isset($envPropertySecond) && $envPropertySecond) {
184+
$secondChunk = $payload->$envPropertySecond;
185+
}
186+
187+
188+
$password = time() . $firstChunk . $secondChunk . $requirementSalt;
172189
}
173190

174191
$user = create_user_record($username, $password, "jwt");

0 commit comments

Comments
 (0)