#!perl

################################################################################################
# Configuration for using LTI authentication.
# To enable this file, uncomment the appropriate lines in localOverrides.conf
# The settings in this file apply to both LTI 1.1 and LTI 1.3 authentication.
# The settings specific to the LTI 1.1 authentication are in authen_LTI_1_1.conf.
# The settings specific to the LTI 1.3 authentication are in authen_LTI_1_3.conf.
################################################################################################

# Set debug_lti_parameters to 1 to enable LTI debugging.  This is useful when setting things up
# for the first time because different LMS systems have different parameters.  Note that for LTI
# 1.1 these debug messages will be displayed in the HTML page.  However, for LTI 1.3 none of the
# debug messages will be displayed in the HTML page due to the nature of how LTI 1.3
# authentication works with automatic form submissions and redirects. These messages can be
# found in the webwork2 app log in that case.
$debug_lti_parameters = 0;

# To get more information on passing grades back to the LMS en mass set debug_lti_grade_passback
# to one.  And set the LTIMassUpdateInterval to 60 (seconds).
$debug_lti_grade_passback = 0;

# This will print into the webwork2 app log the success or failure of updating each user/set.

# Setting both debug_lti_parameters and debug_lti_grade_passback will cause the full requests
# and responses between the LMS and WW to be printed into webwork2 app log file for each
# user/set update of the grade.

# The switches above can be set in course.conf to enable debugging for just one course.

# If you want even more information enable the debug facility in the webwork2.mojolicious.yml
# file.  This will print extensive debugging messages for all courses.

################################################################################################
# Authentication settings
################################################################################################

# This section enables LTI authentication.  If a course uses LTI 1.1 (see $LTIVersion below),
# then the LTIAdvanced module will be used.  If a course uses LTI 1.3 (see $LTIVersion below),
# the LTIAdvantage will be used.  If you know a site will not use one or the other, it can be
# commented out. Failover to Basic_TheLastOption is necessary to authenticate with cookie keys.
$authen{user_module} = [
#	'WeBWorK::Authen::LTIAdvantage',          # first try LTI 1.3
	'WeBWorK::Authen::LTIAdvanced',           # next try LTI 1.1
	'WeBWorK::Authen::Basic_TheLastOption'    # fallback authorization method
];

# List of authentication modules that may be used to enter the admin course.
# This is used instead of $authen{user_module} when logging into the admin course.
# Since the admin course provides overall power to add/delete courses, access
# to this course should be protected by the best possible authentication you
# have available to you.
$authen{admin_module} = [
	#'WeBWorK::Authen::LTIAdvantage',
	#'WeBWorK::Authen::LTIAdvanced',
	'WeBWorK::Authen::Basic_TheLastOption'
];

# Include configurations.  You must uncomment at least one of the following. You may uncomment
# both if the site may be using both LTI 1.1 and 1.3 in different courses. After uncommenting
# the LTI_1_x line, you must copy the file authen_LTI_1_x.conf.dist to authen_LTI_1_x.conf and
# then edit that file to fill in the settings for LTI_1_x.
include('conf/authen_LTI_1_1.conf');
#include('conf/authen_LTI_1_3.conf');

# This is the default LTI version that will be used for the site.  This must be 'v1p1' for LTI
# 1.1 authentication, 'v1p3' for LTI 1.3 authentication, or '' to disable LTI authentication.
# A course may override this setting to use the other version of LTI authentication or to
# disable LTI authentication for the course.
$LTIVersion = 'v1p1';

# WeBWorK will automatically create users when logging in via the LMS for the first time as long
# as the permission level is less than or equal to the permission level of this setting.  For
# security reasons accounts with high permissions should not be auto created via LTI requests.
# Set this variable to 'professor' if you want professor accounts to be created automatically.
$LTIAccountCreationCutoff = 'professor';

# If the following flag is enabled then the user demographic data will be kept up to date with
# the data from the LMS.  If a user's information changes in the LMS then it will change in
# WeBWorK. This means that any changes to the student data via WeBWorK will be overwritten the
# next time the student logs in.
$LMSManageUserData = 1;

# If the preferred module is an external authentication module but the sequence includes an
# internal authentication system, e.g., Basic_TheLastOption, then $external_auth (below) must be
# set to 1 (or true). If the value is 1, then, if the authentication sequence reaches
# Basic_TheLastOption, then WeBWorK::Login will display a screen directing the user back to an
# external authentication system.  This prevents you from attempting to login in to WeBWorK
# directly.
$external_auth = 1;

# NOTE:  If external authentication is disabled then you should probably also prevent students
# from changing their passwords (because they can't use them).  To do this uncomment the
# following.
#$permissionLevels{change_password} = 'ta';

################################################################################################
# Authorization system LTI:  LMS Grade Passback
################################################################################################

# WeBWorK can automatically report grades back to your LMS.  However the system is reasonably
# restrictive.  When you create an LTI link in your LMS you can choose to have that LTI link
# have a grade associated to it.  WeBWorK can report back a single percentage as the "grade" for
# that link.  There are two modes under which this can occur.

# Single Course Grade Mode:  $LTIGradeMode = 'course';
# In this mode you create a single Link/Assignment which points to your WeBWorK Course address.
# Students will receive a LMS grade associated to the Link/Assignment which is determined by
# their percentage total homework grade in WeBWorK.  This total homework grade is the same as
# the grade that is reported on the grades page.  You can change the weight of sets by altering
# the weight of the problems in the set.

# Individual Homework Grade Mode:  $LTIGradeMode = 'homework';
# In this mode you create a single Link/Assignment for *every* homework set in the course.  The
# address should be the address of that set in the Course.  Students will receive a grade for
# each Link/Assignment which is determined by their percentage homework grade on the Set which
# the Link/Assignment points to.  Students need to use the Link/Assignment in the LMS at least
# once to enable grade pass back.  In particular when working in this mode it is recommended that
# you only allow students to log in via the LMS.

# Note: For both of these modes only the grades are passed back.  In particular nothing else
# about the Link/Assignment in the LMS and the homework set in WeBWorK is synchronized.  In
# particular the total number of points/problems, the due dates, the open dates are not kept in
# sync automatically (yet).

# Site Administrator Note for LTI 1.3:  This uses OAuth2 RSA private/public keys.  These keys
# are automatically generated the first time that they are needed.  It is recommended that new
# keys are generated on a regular basis.  At this point, key rotation is not automatic for
# webwork2.  However, it is simple.  Delete the files $webwork2_dir/DATA/lti_private_key.json
# and $webwork2_dir/DATA/lti_public_key.json.  New keys will then be automatically generated the
# next time they are needed.  Probably a good rule of thumb (for now) is to do this at the
# beginning of every term.

$LTIGradeMode = '';
#$LTIGradeMode = 'course';
#$LTIGradeMode = 'homework';

# There are several controls for when to report scores to the LMS. Sometimes these controls
# interact with each other, and the details of how they work may depend on whether $LTIGradeMode
# is set to 'course' or 'homework'. So it is recommended to understand all of them and then
# decide how to set them.

# If $LTICheckPrior is 1, then any time WeBWorK is about to send a score to the LMS, it will
# first request from the LMS what that score currently is. Then if there is no significant
# difference between the LMS score and the WeBWorK score, WeBWorK will not follow through with
# updating the LMS score. This is to avoid frequent insignificant updates to a student's scores
# in the LMS. With some LMSs, students may receive notifications each time a score is updated,
# and setting this variable will prevent too many notifications for them. This does create a
# two-phase process, first querying the current score from the LMS and then actually updating
# the score (if there is a significant difference).

# Additional details:
# - If the LMS score is not 100%, but the WeBWorK score is, then even if the LMS score is only
#   insignificantly less than 100%, it will be updated anyway.
# - If the LMS score is null and the WeBWorK score is 0, this is considered an insignificant
#   difference and the LMS score will not be updated to 0. However if it is after the
#   $LTISendScoresAfterDate (described below), then the null score will be updated to 0 anyway.
# - "Significant" means an absolute difference of 0.001, or 0.1%. At this time this is not
#   configurable.
$LTICheckPrior = 0;

# If $LTIGradeOnSubmit is set to 1, then each time a user submits an answer or scores a test,
# that will trigger WeBWorK possibly reporting a score to the LMS. See $LTICheckPrior for one
# reason that WeBWorK might not ultimately send a score. But there are other reasons too.
# WeBWorK will send the score (the assignment's score if $LTIGradeMode is 'homework' or the
# overall course score if $LTIGradeMode is 'course') to the LMS only if either the assignment's
# $LTISendGradesEarlyThreshold (described below) has been met or if it is past that assignment's
# $LTISendScoresAfterDate (also described below).
$LTIGradeOnSubmit = 1;

# In addition to scores possibly being sent to the LMS upon submission, they can be sent by an
# instructor or admin user using the LTI Grades Update Tool. And thirdly, the system can
# periodically update student scores on the LMS on its own. For all three possible triggers for
# scores to be passed to the LMS, $LTISendScoresAfterDate and $LTISendGradesEarlyThreshold can
# affect what is sent. $LTISendScoresAfterDate can be 'open_date', 'reduced_scoring_date',
# 'due_date', 'answer_date', or 'never'. For a given assignment, if it is after the
# $LTISendScoresAfterDate, then WeBWorK will send scores. If $LTISendScoresAfterDate is 'never',
# then there is no date after which WeBWorK is guaranteed to send scores. In that case, scores
# are only sent when a set's $LTISendGradesEarlyThreshold is met (see below).
# - For 'course' grade passback mode, the assignment will be included in the overall course
#   grade calculation.
# - For 'homework' grade passback mode, the assignment's score will be sent.

# If $LTISendScoresAfterDate is 'reduced_scoring_date' and an assignment has no reduced scoring
# date or reduced scoring is disabled for that assignment, the fallback is to use the due date.

# For a given assignment, if $LTISendScoresAfterDate is 'never' or if it is before the date
# specified by $LTISendScoresAfterDate, WeBWorK may send a score to the LMS depending on the
# value of $LTISendGradesEarlyThreshold. This variable can either be the string 'attempted' or a
# number from 0 to 1. If this variable is 'attempted', a given set must have been attempted for
# the threshold to have been met, and then the score can be used even if it is before the
# $LTISendScoresAfterDate. For a non-test set, 'attempted' just means that some exercise in the
# set was attempted using the Submit button. For a test, 'attempted' means that either there is
# one version with a graded submission, or there are at least two versions.

# If $LTISendGradesEarlyThreshold is a number from 0 to 1, the score for an assignment needs to
# have reached that number for the threshold to be met, and then the score can be used even if
# it is before the $LTISendScoresAfterDate.

#$LTISendScoresAfterDate = 'open_date';
$LTISendScoresAfterDate = 'reduced_scoring_date';
#$LTISendScoresAfterDate = 'due_date';
#$LTISendScoresAfterDate = 'answer_date';
#$LTISendScoresAfterDate = 'never';

$LTISendGradesEarlyThreshold = 'attempted';
#$LTISendGradesEarlyThreshold = 0;
#$LTISendGradesEarlyThreshold = 0.7;
#$LTISendGradesEarlyThreshold = 1;

# The system periodically updates student scores on the LMS. If it has been at least this many
# seconds since the last mass passback event and someone in the course does anything to load a
# page, then a new mass passback job will begin. Set this to -1 to disable mass passback.
$LTIMassUpdateInterval = 86400;


################################################################################################
# Add an 'LTI' tab to the Course Configuration page
################################################################################################

# Uncomment any of the variables listed in the @LTIConfigVariables array below if you would like
# the Course Configuration page to have an LTI tab, granting the course instructor easy access
# to some of the LTI settings. You may leave some of the variables commented out if you would
# like to omit them from the options in this tab.  If all variables are left commented out, then
# the tab will not be shown.  Note that the default values for the variables that will be shown
# in the LTI tab are the values that are set above.  Further note that only the commented out
# variables listed below may be added to the LTI config tab.  In addition, only the variables that
# pertain to the active LTI version will be shown in the tab. Warning: Allowing users to modify
# the BasicConsumerSecret for LTI 1.1 or the IDs, URLs, etc for LTI 1.3 can expose the values
# of the variables and allow users to lock themselves out of logging in via an LMS.
@LTIConfigVariables = (
	#'LTI{v1p1}{LMS_name}',
	#'LTI{v1p3}{LMS_name}',
	#'LTI{v1p1}{LMS_url}',
	#'LTI{v1p3}{LMS_url}',
	#'external_auth',
	#'LTIGradeMode',
	#'LTICheckPrior',
	#'LTIGradeOnSubmit',
	#'LTISendScoresAfterDate',
	#'LTISendGradesEarlyThreshold',
	#'LTIMassUpdateInterval',
	#'LMSManageUserData',
	#'LTI{v1p1}{BasicConsumerSecret}',
	#'LTI{v1p3}{PlatformID}',
	#'LTI{v1p3}{ClientID}',
	#'LTI{v1p3}{DeploymentID}',
	#'LTI{v1p3}{PublicKeysetURL}',
	#'LTI{v1p3}{AccessTokenURL}',
	#'LTI{v1p3}{AccessTokenAUD}',
	#'LTI{v1p3}{AuthReqURL}',
	#'debug_lti_parameters',
	#'lms_context_id'
);
$LTI{v1p1}{BasicConsumerSecret} = 'moodle-wics';

# The consumer key is entered in the LMS request form, and needs to match the entry here if this
# is set.  This is only used for content item selection requests from an LMS, and this does not
# even need to be set for that unless there are multiple courses from different LMS's that have
# the same LMS context id and both use a course on this webwork2 server.  In that case each LMS
# must use a different consumer key, and the correct consumer keys should be set in the
# course.conf file for each course. If this server is a tool provider for multiple LMS's, then
# it is recommended that this be set. Usually it is not useful to set this here.  However, if
# most courses use one LMS and only a few use another, then the consumer key for the first LMS
# could be set here, and then this would only need to be set in the course.conf files for the
# few courses use a different LMS.
$LTI{v1p1}{ConsumerKey} = 'moodle-wics';


# By default only admin users can modify the LTI secrets and lms_context_id. The following
# permissions need to be modified to allow other users the permission to modify the values.
#$permissionLevels{'change_config_LTI{v1p1}{BasicConsumerSecret}'} = "admin",
#$permissionLevels{'change_config_LTI{v1p3}{PlatformID}'}          = "admin",
#$permissionLevels{'change_config_LTI{v1p3}{ClientID}'}            = "admin",
#$permissionLevels{'change_config_LTI{v1p3}{DeploymentID}'}        = "admin",
#$permissionLevels{'change_config_LTI{v1p3}{PublicKeysetURL}'}     = "admin",
#$permissionLevels{'change_config_LTI{v1p3}{AccessTokenURL}'}      = "admin",
#$permissionLevels{'change_config_LTI{v1p3}{AccessTokenAUD}'}      = "admin",
#$permissionLevels{'change_config_LTI{v1p3}{AuthReqURL}'}          = "admin",
#$permissionLevels{'change_config_lms_context_id'}                 = "admin",

# Note that the lms_context_id is actually a database setting. It must be set for a course in
# order for the instructor to utilize LTI content selection. This can also be set in the admin
# course.

1;    # final line of the file to reassure perl that it was read properly.
