@@ -120,8 +120,7 @@ private function attempt_jwt_login() {
120
120
* For some environments, this will be necessary, but for ADL's P1 deployment
121
121
* this doesn't add any extra security.
122
122
*/
123
- $ checkIssuer = getenv ("MOODLE_JWT_CHECK_ISSUER " );
124
- if (isset ($ checkIssuer ) && $ checkIssuer ) {
123
+ if ($ this ->has_env_bool ("MOODLE_JWT_CHECK_ISSUER " )) {
125
124
126
125
$ issuer = $ payload ->iss ;
127
126
$ issuerExpected = getenv ("MOODLE_JWT_ISSUER " );
@@ -136,8 +135,7 @@ private function attempt_jwt_login() {
136
135
* For Client, this is a bit less obvious as these can be auto-generated by the
137
136
* deployment environment and should be provided by the Ops / Hosting team.
138
137
*/
139
- $ checkClient = getenv ("MOODLE_JWT_CHECK_CLIENT " );
140
- if (isset ($ checkClient ) && $ checkClient ) {
138
+ if ($ this ->has_env_bool ("MOODLE_JWT_CHECK_CLIENT " )) {
141
139
142
140
$ client = $ payload ->azp ;
143
141
$ clientExpected = getenv ("MOODLE_JWT_CLIENT_ID " );
@@ -160,8 +158,7 @@ private function attempt_jwt_login() {
160
158
* approach will be to simply create a pseudo-randomized password
161
159
* for this account, which will be blocked from manual entry anyway.
162
160
*/
163
- $ assignRandomPassword = getenv ("MOODLE_JWT_ASSIGN_RANDOM_PASSWORD " );
164
- if (isset ($ assignRandomPassword ) && $ assignRandomPassword ) {
161
+ if ($ this ->has_env_bool ("MOODLE_JWT_ASSIGN_RANDOM_PASSWORD " )) {
165
162
166
163
/**
167
164
* The "salt" here will simply be a character block to satisfy password reqs.
@@ -178,12 +175,16 @@ private function attempt_jwt_login() {
178
175
$ firstChunk = $ payload ->sub ;
179
176
$ secondChunk = $ payload ->iss ;
180
177
181
- if (isset ($ envPropertyFirst ) && $ envPropertyFirst ) {
182
- $ firstChunk = $ payload ->$ envPropertyFirst ;
178
+ if ($ envPropertyFirst != false ) {
179
+ if (property_exists ($ payload , $ envPropertyFirst )) {
180
+ $ firstChunk = $ payload ->$ envPropertyFirst ;
181
+ }
183
182
}
184
183
185
- if (isset ($ envPropertySecond ) && $ envPropertySecond ) {
186
- $ secondChunk = $ payload ->$ envPropertySecond ;
184
+ if ($ envPropertySecond != false ) {
185
+ if (property_exists ($ payload , $ envPropertySecond )) {
186
+ $ secondChunk = $ payload ->$ envPropertySecond ;
187
+ }
187
188
}
188
189
189
190
@@ -231,11 +232,10 @@ private function attempt_jwt_login() {
231
232
*/
232
233
private function get_expected_username ($ cert ) {
233
234
234
- $ envUseEDIPI = getenv ("MOODLE_JWT_USE_EDIPI " );
235
235
$ envEDIPIProperty = getenv ("MOODLE_JWT_EDIPI_PROPERTY " );
236
236
237
- $ useEDIPI = isset ( $ envUseEDIPI ) && strcasecmp ( $ envUseEDIPI , " true " );
238
- $ configuredForEDIPI = isset ( $ envEDIPIProperty) ;
237
+ $ useEDIPI = $ this -> has_env_bool ( " MOODLE_JWT_USE_EDIPI " );
238
+ $ configuredForEDIPI = $ envEDIPIProperty != false ;
239
239
240
240
if ($ useEDIPI && $ configuredForEDIPI ) {
241
241
$ edipiNumber = $ this ->get_edipi_number ($ cert , $ envEDIPIProperty );
@@ -248,7 +248,7 @@ private function get_expected_username($cert) {
248
248
249
249
$ envCustomProperty = getenv ("MOODLE_JWT_USERNAME_PROPERTY " );
250
250
251
- $ useCustomProperty = isset ( $ envCustomProperty) ;
251
+ $ useCustomProperty = $ envCustomProperty != false ;
252
252
$ hasCustomProperty = property_exists ($ cert , $ envCustomProperty );
253
253
254
254
if ($ useCustomProperty && $ hasCustomProperty ) {
@@ -304,6 +304,13 @@ private function decode_base_64($encodedStr) {
304
304
return base64_decode ($ b );
305
305
}
306
306
307
+ private function has_env_bool ($ variableName ) {
308
+ $ value = getenv ($ variableName );
309
+ $ exists = $ value != false ;
310
+
311
+ return $ exists && strcasecmp ($ value , "true " );
312
+ }
313
+
307
314
/**
308
315
* Unused atm.
309
316
*/
0 commit comments