You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't create users for LTI users that do not have permission to login.
Currently if `$permissionLevels{login} = 'professor'` and a user signs
in via LTI that would be assigned the role of "student", then webwork2
creates the user and signs the user in. However, on subsequent LTI
logins authentication fails. This refuses to create a user if the
requested role would not have permission to login.
Clean up the error messages some. There is a lot of work left to
do on this. The LTIAdvance.pm module has an extremely poor design for
error handling and messaging to go with those errors. The
LTIAdvantage.pm module is only a tad better (I largely just copied the
poor design of the LTIAdvanced.pm module). The `log_error` key is set
and appended to numerous times, frequently resulting in a long run on
message that doesn't really make sense. Also, there were some of these
errors that were adding "LOGIN FAILED". That was removed because The
`Authen.pm` code always prepends that and that resulted in logs with
"LOGIN FAILED LOGIN FAILED ...".
The `authenticate` method is expected to return either 1 or a message
indicating the failure. Currently it returns either 1 or 0. As a
result the messages that are set in the `authenticate` method go into
the abyss. Those messages should be returned instead of setting
`$self->{error}`. Note that the method can still return 0 if no message
should be set (as in the case of the OAuth token failing to verify for
LTI 1.1).
For LTI 1.3 make sure that the fallback_source_of_username is set before
attempting to use it. Otherwise the claim extraction fails and it
results in a database error later.
Fix a minor issue in the authen_LTI.conf.dist file. The
permissionLevels lines should end with semicolons, not commas.
Copy file name to clipboardExpand all lines: lib/WeBWorK/Authen/LTIAdvanced.pm
+69-78Lines changed: 69 additions & 78 deletions
Original file line number
Diff line number
Diff line change
@@ -117,10 +117,9 @@ sub get_credentials {
117
117
# Determine the WW user_id to use, if possible
118
118
119
119
if (!$ce->{LTI}{v1p1}{preferred_source_of_username}) {
120
-
warn
121
-
"LTI is not properly configured (no preferred_source_of_username). Please contact your instructor or system administrator.";
122
-
$self->{error} = $c->maketext(
123
-
"There was an error during the login process. Please speak to your instructor or system administrator.");
120
+
$self->{error} = $c->maketext("There was an error during the login process. "
121
+
. "Please speak to your instructor or system administrator.");
122
+
warn"LTI is not properly configured (no preferred_source_of_username).\n"if$ce->{debug_lti_parameters};
124
123
debug("No preferred_source_of_username in "
125
124
. $c->ce->{'courseName'}
126
125
. " so LTIAdvanced::get_credentials is returning a 0\n");
@@ -228,17 +227,17 @@ sub get_credentials {
228
227
warn"================================\n";
229
228
}
230
229
if (!defined($self->{user_id})) {
231
-
croak
232
-
"LTIAdvanced was unable to create a username from the data provided with the current settings. Set \$debug_lti_parameters=1 in authen_LTI.conf to debug";
230
+
croak"LTIAdvanced was unable to create a username from the data provided with the current settings. "
231
+
. "Set \$debug_lti_parameters=1 in authen_LTI.conf to debug";
233
232
}
234
233
235
234
$self->{login_type} = "normal";
236
235
$self->{credential_source} = "LTIAdvanced";
237
236
debug("LTIAdvanced::get_credentials is returning a 1\n");
238
237
return 1;
239
238
}
240
-
warn
241
-
"LTI is not properly configured (failed to set user_id from preferred_source_of_username or fallback_source_of_username). Please contact your instructor or system administrator.";
239
+
warn"LTI is not properly configured (failed to set user_id from preferred_source_of_username or "
240
+
. "fallback_source_of_username). Please contact your instructor or system administrator.";
242
241
$self->{error} = $c->maketext(
243
242
"There was an error during the login process. Please speak to your instructor or system administrator.");
244
243
debug("LTIAdvanced::get_credentials is returning a 0\n");
. "Check the Consumer Secret and that the URL in the LMS exactly matches the WeBWorK URL.";
435
428
if ($ce->{debug_lti_parameters}) {
436
-
warn(
437
-
"OAuth verification failed. Check the Consumer Secret and that the URL in the LMS exactly matches the WeBWorK URL as defined in site.conf. E.G. Check that if you have https in the LMS url then you have https in \$server_root_url in site.conf"
438
-
);
429
+
warn("OAuth verification failed. Check the Consumer Secret and that the URL in the LMS exactly "
430
+
. "matches the WeBWorK URL as defined in site.conf. E.G. Check that if you have https in the "
431
+
. "LMS url then you have https in \$server_root_url in site.conf");
439
432
}
440
433
return 0;
441
434
} else {
442
435
debug("OAuth verification SUCCEEDED !!");
443
436
444
437
my$userID = $self->{user_id};
445
438
446
-
# Indentation of the internal blocks below was modified to follow
447
-
# the WW coding standard; however, the leading indentation of the
448
-
# if/elsif/closing '}' was kept as in the original code for now.
449
-
# Thus the apparenly overlarge indentation below.
450
439
if (!$db->existsUser($userID)) { # New User. Create User record
451
440
if ($ce->{block_lti_create_user}) {
452
-
# We don't yet have the next string in the PO/POT files - so the next line is disabled.
453
-
# $c->maketext("Account creation is currently disabled in this course. Please speak to your instructor or system administrator.");
454
441
$self->{log_error} .=
455
442
"Account creation blocked by block_lti_create_user setting. Did not create user $userID.";
456
-
if ($ce->{debug_lti_parameters}) {
457
-
warn(
458
-
"Account creation is currently disabled in this course. Please speak to your instructor or system administrator."
459
-
);
460
-
}
461
-
return 0;
443
+
warn"Account creation is currently disabled in this course. "
444
+
. "Please speak to your instructor or system administrator."
445
+
if$ce->{debug_lti_parameters};
446
+
return$c->maketext("Account creation is currently disabled in this course. "
447
+
. "Please speak to your instructor or system administrator.");
462
448
} else {
463
449
# Attempt to create the user, and warn if that fails.
464
-
unless ($self->create_user()) {
465
-
$c->maketext(
466
-
"There was an error during the login process. Please speak to your instructor or system administrator."
467
-
);
450
+
unless ($self->create_user) {
468
451
$self->{log_error} .= "Failed to create user $userID.";
469
-
if($ce->{debug_lti_parameters}) {
470
-
warn("Failed to create user $userID.");
471
-
}
452
+
warn"Failed to create user $userID.\n"if$ce->{debug_lti_parameters};
453
+
return$c->maketext('Unable to create a WeBWorK user. '
454
+
. 'Please speak to your instructor or system administrator.');
472
455
}
473
456
}
474
457
} elsif ($ce->{LMSManageUserData}) {
475
-
$self->{initial_login} = 1
476
-
; # Set here so login gets logged, even for accounts which maybe_update_user() would not modify or when it fails to update
477
-
# Existing user. Possibly modify demographic information and permission level.
458
+
# Set here so login gets logged, even for accounts which maybe_update_user()
459
+
# would not modify or when it fails to update.
460
+
$self->{initial_login} = 1;
461
+
462
+
# Existing user. Possibly modify demographic information and permission level.
478
463
unless ($self->maybe_update_user()) {
479
-
# Do not fail the login if data update failed
480
-
# FIXME - In the future we would like the message below (and other warn messages in this file) to be sent via maketext.
481
-
warn(
482
-
"The system failed to update some of your account information. Please speak to your instructor or system administrator."
483
-
);
464
+
# Do not fail the login if data update failed
465
+
warn("The system failed to update some of your account information. "
466
+
. "Please speak to your instructor or system administrator.");
484
467
}
485
468
} else {
486
469
# Set here so login gets logged when $ce->{LMSManageUserData} is false
@@ -501,9 +484,8 @@ sub authenticate {
501
484
}
502
485
503
486
debug("LTIAdvanced is returning a failed authentication");
504
-
$self->{error} =$c->maketext(
487
+
return$c->maketext(
505
488
"There was an error during the login process. Please speak to your instructor or system administrator.");
0 commit comments