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
+70-78Lines changed: 70 additions & 78 deletions
Original file line number
Diff line number
Diff line change
@@ -117,10 +117,10 @@ 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
+
warn"LTI is not properly configured (no preferred_source_of_username). "
121
+
. "Please contact your instructor or system administrator.";
122
+
$self->{error} = $c->maketext("There was an error during the login process. "
123
+
. "Please speak to your instructor or system administrator.");
124
124
debug("No preferred_source_of_username in "
125
125
. $c->ce->{'courseName'}
126
126
. " so LTIAdvanced::get_credentials is returning a 0\n");
@@ -228,17 +228,17 @@ sub get_credentials {
228
228
warn"================================\n";
229
229
}
230
230
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";
231
+
croak"LTIAdvanced was unable to create a username from the data provided with the current settings. "
232
+
. "Set \$debug_lti_parameters=1 in authen_LTI.conf to debug";
233
233
}
234
234
235
235
$self->{login_type} = "normal";
236
236
$self->{credential_source} = "LTIAdvanced";
237
237
debug("LTIAdvanced::get_credentials is returning a 1\n");
238
238
return 1;
239
239
}
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.";
240
+
warn"LTI is not properly configured (failed to set user_id from preferred_source_of_username or "
241
+
. "fallback_source_of_username). Please contact your instructor or system administrator.";
242
242
$self->{error} = $c->maketext(
243
243
"There was an error during the login process. Please speak to your instructor or system administrator.");
244
244
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
429
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
-
);
430
+
warn("OAuth verification failed. Check the Consumer Secret and that the URL in the LMS exactly "
431
+
. "matches the WeBWorK URL as defined in site.conf. E.G. Check that if you have https in the "
432
+
. "LMS url then you have https in \$server_root_url in site.conf");
439
433
}
440
434
return 0;
441
435
} else {
442
436
debug("OAuth verification SUCCEEDED !!");
443
437
444
438
my$userID = $self->{user_id};
445
439
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
440
if (!$db->existsUser($userID)) { # New User. Create User record
451
441
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
442
$self->{log_error} .=
455
443
"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;
444
+
warn"Account creation is currently disabled in this course. "
445
+
. "Please speak to your instructor or system administrator."
446
+
if$ce->{debug_lti_parameters};
447
+
return$c->maketext("Account creation is currently disabled in this course. "
448
+
. "Please speak to your instructor or system administrator.");
462
449
} else {
463
450
# 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
-
);
451
+
unless ($self->create_user) {
468
452
$self->{log_error} .= "Failed to create user $userID.";
469
-
if($ce->{debug_lti_parameters}) {
470
-
warn("Failed to create user $userID.");
471
-
}
453
+
warn"Failed to create user $userID.\n"if$ce->{debug_lti_parameters};
454
+
return$c->maketext('Unable to create a WeBWorK user. '
455
+
. 'Please speak to your instructor or system administrator.');
472
456
}
473
457
}
474
458
} 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.
459
+
# Set here so login gets logged, even for accounts which maybe_update_user()
460
+
# would not modify or when it fails to update.
461
+
$self->{initial_login} = 1;
462
+
463
+
# Existing user. Possibly modify demographic information and permission level.
478
464
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
-
);
465
+
# Do not fail the login if data update failed
466
+
warn("The system failed to update some of your account information. "
467
+
. "Please speak to your instructor or system administrator.");
484
468
}
485
469
} else {
486
470
# Set here so login gets logged when $ce->{LMSManageUserData} is false
@@ -501,9 +485,8 @@ sub authenticate {
501
485
}
502
486
503
487
debug("LTIAdvanced is returning a failed authentication");
504
-
$self->{error} =$c->maketext(
488
+
return$c->maketext(
505
489
"There was an error during the login process. Please speak to your instructor or system administrator.");
0 commit comments